Java – Allow FileProvider content providers in 2 lists?

Allow FileProvider content providers in 2 lists?… here is a solution to the problem.

Allow FileProvider content providers in 2 lists?

I have this in my app list:

<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 scan library and I also have it in list:

    <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 that I’m getting this error and don’t know how to fix it: 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 do you get these 2 vendors to work together?
I also try tools:replace="android:value" instead of working.

Solution

The author of your scanned library needs to read this blog post of mine from 2017

Since they don’t, you need to do the steps yourself:

  • Create a normal subclass of the FileProvider

  • Use the subclass element in your <provider>

This will provide you with functionality while avoiding conflicts between FileProvider and libraries.

Related Problems and Solutions