【问题标题】:AndroidManifest merge error using FileProvider使用 FileProvider 的 AndroidManifest 合并错误
【发布时间】:2017-03-19 23:55:58
【问题描述】:

我正在尝试使用在其 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>

所以它显然给出了一个 Manifest 合并错误:

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

这建议“将 'tools:replace="android:authorities"' 添加到 AndroidManifest.xml 中的元素以覆盖”。

所以我像这样在我的应用的 AndroidManifest.xml 中添加tools:replace="android:authorities"

<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


    【解决方案1】:

    要解决这个问题,有两种选择:要么更改清单以使用与 android.support.v4.content.FileProvider 不同的类,要么创建 PR/问题,要求库所有者更改他/她的(这是最好的情况)场景)。

    如果您想快速修复,只需创建一个扩展 FileProvider 的类,例如:

    import android.support.v4.content.FileProvider;
    
    public class MyFileProvider extends FileProvider {
    }
    

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

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

    【讨论】:

    • 很好的答案!谢谢!
    • FileProvider 应该被扩展以覆盖任何默认行为,而不是修复名称冲突。
    【解决方案2】:

    添加到您的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>
    

    【讨论】:

    • 这个答案对我有用。您知道如何/为什么解决“清单合并”问题吗?
    【解决方案3】:

    对于使用 sdk 28 及更高版本的用户,如果您要迁移到 androidx,解决​​方案是:

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

    【讨论】:

      【解决方案4】:

      由于您不更改提供程序中的任何值,因此您无需将其包含在清单中。只需删除这些行。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多