Skip to content

fix(android): remove Apache Tika dependency for MIME type detection - #2104

Merged
navaronbracke merged 2 commits into
vicajilau:masterfrom
ryanaidilp:fix/2101-remove-tika-android
Jul 31, 2026
Merged

navaronbracke merged 2 commits into
vicajilau:masterfrom
ryanaidilp:fix/2101-remove-tika-android

Conversation

@ryanaidilp

Copy link
Copy Markdown
Contributor

Summary

  • Removes the Apache Tika dependency (~300 KB) from the legacy android/ implementation, used only to detect a MIME type for saveFile().
  • MIME types are now resolved from the file name extension via MimeTypeMap (with the existing CSV special-case preserved), falling back to URLConnection.guessContentTypeFromStream content sniffing only when the file name has no usable extension.
  • Removes the now-unused Tika proguard rules and the tika-core dependency from build.gradle.kts.

Companion PRs:

  • Backport of this same fix targeting the 11.0.x line (based on v11.0.2).
  • A separate PR applying the same fix to file_picker_android specifically.

Fixes #2101

Test plan

  • flutter build apk --debug in example/ compiles cleanly against this change.
  • Java/Kotlin code in this plugin has no existing unit test harness (per CONTRIBUTING.md, native platform code is not currently unit tested), so verification was via compilation and manual review of the MIME-mapping logic against the previous Tika-based behavior.

Tika added ~300 KB to the Android binary just to detect a MIME type in
saveFile(). MIME types are now resolved from the file name extension
via MimeTypeMap, with URLConnection.guessContentTypeFromStream as a
content-sniffing fallback when no usable extension is available.

Fixes vicajilau#2101
private const val CSV_MIME_TYPE = "text/csv"
// Fallback MIME type used when neither the file name extension nor
// content sniffing can determine a type, matching the value used by
// most content-detection libraries (and previously Apache Tika) for

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since Tika will be removed, I would remove the reference to it in docs. I don't think that years into the future, when someone reads this code, they will have the original context.

Suggested change
// most content-detection libraries (and previously Apache Tika) for
// most content-detection libraries for


// Sniffs [bytes] for a MIME type using URLConnection's built-in magic-number
// detection. This is a best-effort fallback for when the file name has no
// usable extension, without pulling in a full content-detection dependency.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same reason as above

Suggested change
// usable extension, without pulling in a full content-detection dependency.
// usable extension.

Comment thread CHANGELOG.md Resolved
Trims the "(and previously Apache Tika)" and "without pulling in a
full content-detection dependency" asides per review feedback -
they only make sense with context that won't exist once Tika is
fully removed from the codebase.
@navaronbracke
navaronbracke merged commit 0104853 into vicajilau:master Jul 31, 2026
11 checks passed
navaronbracke pushed a commit that referenced this pull request Jul 31, 2026
#2104 merged before this correction landed on that branch. This fix
targets the v11.x hotfix release, so the CHANGELOG entry belongs
under its own 11.0.3 heading (positioned above 11.0.2 to match
release chronology), not the unreleased 12.0.0-beta.8 bucket.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Suggestion: Remove Apache Tika dependency on Android to reduce app size

2 participants