AndroidManifest使用FileProvider合并错误

问题描述 投票:15回答:3

我试图使用具有这种在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>

我有我的应用程序的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>

因此,它显然给出了一个清单合并错误:

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

这表明,以“补充‘工具:更换=‘机器人:当局’’以元素在AndroidManifest.xml中重写”。

所以,我想补充tools:replace="android:authorities"这样的,在我的应用程序的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">

然后我得到这个错误:

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

同样的情况与tools:replace="android.support.v4.content.FileProvider"

我在想什么?

android android-manifest
3个回答
28
投票

为了解决这个问题有两个选择:要么你改变你的清单以使用不同的类比android.support.v4.content.FileProvider或创建一个PR /问题问的lib的所有者改变他/她的(这将是最好的情况下)。

如果你想速战速决,只创建一个扩展FileProvider如类:

import android.support.v4.content.FileProvider;

public class MyFileProvider extends FileProvider {
}

并在您的清单文件将其更改为:

<provider android:name=".MyFileProvider" ... >

13
投票

添加到您的AndroidManifest.xml文件时,application标签内:

    <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
投票

既然你没有在供应商变更的任何值,你不需要把它列入你的清单。只是删除这些行。

© www.soinside.com 2019 - 2024. All rights reserved.