[英]AndroidManifest merge error using FileProvider
I'm trying to use a library that has this in its AndroidManifest.xml:我正在尝试使用在其 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:我的应用程序的 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:所以它显然给出了一个 Manifest 合并错误:
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".这建议“将 'tools:replace="android:authorities"' 添加到 AndroidManifest.xml 中的元素以覆盖”。
So I add tools:replace="android:authorities"
like this, in my app's 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">
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"
. tools:replace="android.support.v4.content.FileProvider"
发生同样的情况。
What am I missing?我错过了什么?
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).要解决这个问题,有两种选择:要么更改清单以使用与
android.support.v4.content.FileProvider
不同的类,要么创建一个 PR/问题,要求库的所有者更改他/她的(这将是最好的情况)。
If you want a quick fix, just create a class that extends FileProvider
such as:如果您想要快速修复,只需创建一个扩展
FileProvider
的类,例如:
import android.support.v4.content.FileProvider;
public class MyFileProvider extends FileProvider {
}
and in your manifest file you change it to:并在您的清单文件中将其更改为:
<provider android:name=".MyFileProvider" ... >
Add to your AndroidManifest.xml
file, inside the application
tag:添加到您的
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>
For those using sdk 28 and up, if you are migrating to androidx, solution is :对于使用 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>
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.
只需删除这些行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.