wordpress-mobile / wordpress-mobile/GutenbergKit
FileProvider declaration collides with host app's FileProvider in the manifest merger
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 29
- Forks
- 6
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 41
Description
Summary
GBK's Android manifest declares <provider android:name="androidx.core.content.FileProvider"> directly, which the AGP manifest merger treats as a duplicate of any host app's own FileProvider — regardless of android:authorities. Host apps that already declare a FileProvider with the canonical AndroidX class name (the documented pattern) hit a build failure on first integration of v0.17.x and have to retrofit tools:replace to ship.
Repro
Host app's AndroidManifest.xml:
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>
After upgrading to org.wordpress.gutenbergkit:android:v0.17.1:
Attribute provider#androidx.core.content.FileProvider@authorities
value=(com.example.app.provider) from (unknown)
is also present at [org.wordpress.gutenbergkit:android:v0.17.1]
AndroidManifest.xml:19:13-74
value=(com.example.app.gutenberg.fileprovider).
Suggestion: add 'tools:replace="android:authorities"' to <provider>
element at AndroidManifest.xml to override.
A second error on the FILE_PROVIDER_PATHS meta-data resource (@xml/provider_paths vs @xml/gbk_file_paths) follows the same shape.
Root Cause
Per the manifest merger docs, <provider> elements are matched by android:name. Two declarations of androidx.core.content.FileProvider are treated as the same element; conflicting android:authorities and child meta-data become hard errors.
The current manifest comment in Gutenberg/src/main/AndroidManifest.xml:
Authority is keyed off the host app's applicationId so it won't collide with one a host app already declares.
— is correct at the Android runtime layer (where providers route by authority), but the AGP manifest merger collides earlier, on the class name. The runtime-uniqueness guarantee doesn't help the build.
Suggested Fix
Subclass FileProvider:
// android/Gutenberg/src/main/java/org/wordpress/gutenberg/GutenbergFileProvider.kt
package org.wordpress.gutenberg
import androidx.core.content.FileProvider
class GutenbergFileProvider : FileProvider()
<provider
android:name="org.wordpress.gutenberg.GutenbergFileProvider"
android:authorities="${applicationId}.gutenberg.fileprovider"
... />
FileProvider has a public no-arg constructor; the subclass adds nothing but a unique android:name. The merger now keys on a distinct class, the host app's FileProvider stays untouched, and consumers need no workaround.
This is the same pattern Chucker uses (ChuckerFileProvider), which is why Chucker coexists with a host-declared androidx.core.content.FileProvider without ever surfacing this issue.
Consumer Workaround (for now)
Hosts integrating v0.17.x today need to fold the GBK authority and paths into their own provider:
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider;${applicationId}.gutenberg.fileprovider"
android:exported="false"
android:grantUriPermissions="true"
tools:replace="android:authorities">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"
tools:replace="android:resource"/>
</provider>
…and copy gbk_camera (<cache-path name="gbk_camera" path="camera/"/>) into the host's provider_paths.xml. Awkward, and easy to forget on subsequent GBK updates if GBK ever adds more paths.
Affected
org.wordpress.gutenbergkit:android:v0.17.0and later (introduced when the camera-capture FileProvider landed).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with android/Gutenberg/src/main/AndroidManifest.xml and inspect the existing FileProvider declaration and its comment. Review the proposed android/Gutenberg/src/main/java/org/wordpress/gutenberg/GutenbergFileProvider.kt entry point, then verify the manifest merger succeeds for an app that already declares androidx.core.content.FileProvider. Done means the host provider remains untouched and the GBK provider no longer causes authority or FILE_PROVIDER_PATHS conflicts.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, kotlin
- Domain
- build-system, mobile
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100