RGS
RGS

Reputation: 4253

Allow FileProvider content provider in 2 manifests?

I have this in my app manifest:

<provider
    android:name="androidx.core.content.FileProvider"
    android:authorities="com.my.app"
    android:exported="false"
    android:grantUriPermissions="true">
    <meta-data
        android:name="android.support.FILE_PROVIDER_PATHS"
        android:resource="@xml/provider_paths"/>
</provider>

I also have a scanlibrary that has it too in its manifest:

    <provider
        android:name="androidx.core.content.FileProvider"
        android:authorities="com.scanlibrary.provider"
        android:exported="false"
        android:grantUriPermissions="true">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/provider_paths"/>
    </provider>

The problem is I get this error and don't know how to solve: Manifest merger failed : Attribute provider#androidx.core.content.FileProvider@authorities value=(com.my.app) from AndroidManifest.xml:32:13-49 AndroidManifest.xml:32:13-59 value=(com.scanlibrary.provider). Suggestion: add 'tools:replace="android:authorities"' to <provider> element at AndroidManifest.xml:30:9-38:20 to override.

How to allow this 2 providers to work together? I also try tools:replace="android:value" and not work.

Upvotes: 3

Views: 1395

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006914

The authors of your scan library need to read this blog post of mine from 2017.

Since they didn't, you will need to take those steps yourself:

  • Create a trivial subclass of FileProvider

  • Use that subclass in your <provider> element

This will give you the functionality, while avoiding the FileProvider collision with the library.

Upvotes: 3

Related Questions