24

I'm trying to use a library that has this in its AndroidManifest.xml:

    <provider
        android:name="android.support.v4.content.FileProvider"
        android:authorities="${applicationId}.imagepicker.provider"
        android:exported="false"
        android:grantUriPermissions="true">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/provider_paths"/>
    </provider>

I have the same tag in my app's AndroidManifest.xml:

    <provider
        android:name="android.support.v4.content.FileProvider"
        android:authorities="@string/FileProviderAuthority"
        android:exported="false"
        android:grantUriPermissions="true">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/file_paths"></meta-data>
    </provider>

So it obviously gives a Manifest merger error:

Error:Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed with multiple errors, see logs

Which suggests to "add 'tools:replace="android:authorities"' to element at AndroidManifest.xml to override".

So I add tools:replace="android:authorities" like this, in my app's AndroidManifest.xml:

<application
    tools:replace="android:authorities"
    android:name=".appcontroller.AppController"
    android:allowBackup="true"
    android:hardwareAccelerated="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:largeHeap="true"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

And then I get this error:

Error:
tools:replace specified at line:25 for attribute android:authorities, but no new value specified

The same happens with tools:replace="android.support.v4.content.FileProvider".

What am I missing?

4 Answers 4

48

To solve this there are two options: either you change your manifest to use a different class than android.support.v4.content.FileProvider or you create a PR/issue asking the owner of the lib to change his/hers (that would be the best case scenario).

If you want a quick fix, just create a class that extends FileProvider such as:

import android.support.v4.content.FileProvider;

public class MyFileProvider extends FileProvider {
}

and in your manifest file you change it to:

<provider android:name=".MyFileProvider" ... >
2
  • Great answer! Thank you!
    – Sjd
    Sep 14, 2017 at 9:42
  • 3
    FileProvider should be extended in order to override any of the default behavior, not to fix name collision.
    – JP Ventura
    Jan 15, 2018 at 22:06
30

Add to your AndroidManifest.xml file, inside the application tag:

    <provider
        android:name="android.support.v4.content.FileProvider"
        android:authorities="${applicationId}.fileprovider"
        android:exported="false"
        android:grantUriPermissions="true"
        tools:replace="android:authorities">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/file_paths"
            tools:replace="android:resource" />
    </provider>
1
  • 1
    This answer works for me. Do you know how/why this fixes the "manifest merger" issue? Jun 5, 2018 at 19:52
10

For those using sdk 28 and up, if you are migrating to androidx, solution is :

<provider
    android:name="androidx.core.content.FileProvider"
    android:authorities="${applicationId}.fileprovider"
    android:exported="false"
    android:grantUriPermissions="true"
    tools:replace="android:authorities">
    <meta-data
        android:name="android.support.FILE_PROVIDER_PATHS"
        android:resource="@xml/file_paths"/>
</provider>
1

Since you do not change any of the values in the provider, you do not need to include it in your manifest. Just remove those lines.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.