Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AndroidManifest merge error using FileProvider

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?

like image 398
RominaV Avatar asked Mar 19 '17 23:03

RominaV


4 Answers

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" ... >
like image 165
douglas.iacovelli Avatar answered Nov 09 '22 13:11

douglas.iacovelli


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>
like image 26
JP Ventura Avatar answered Nov 09 '22 11:11

JP Ventura


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>
like image 10
Br0thazS0ul Avatar answered Nov 09 '22 12:11

Br0thazS0ul


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.

like image 1
Code-Apprentice Avatar answered Nov 09 '22 12:11

Code-Apprentice