AndroidManifest merge error using FileProvider

2019-02-06 06:29发布

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?

3条回答
家丑人穷心不美
2楼-- · 2019-02-06 07:01

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" ... >
查看更多
3楼-- · 2019-02-06 07:04

Add to your AndroidManifest.xml file:

    <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>
查看更多
闹够了就滚
4楼-- · 2019-02-06 07:09

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.

查看更多
登录 后发表回答