问题
Error: Attribute application@appComponentFactory value=(androidx.core.app.CoreComponentFactory) from AndroidManifest.xml:24:18-86 is also present at AndroidManifest.xml:22:18-91 value=(android.support.v4.app.CoreComponentFactory). Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:26:5-186:19 to override. assistingAgriculture.app main manifest (this file), line 23
详细问题
笔者进行Android项目开发,启动项目报错
Caused by: java.lang.RuntimeException: Manifest merger failed with multiple errors, see logs
查看Merged Manifest
具体报错信息如下
Error: Attribute application@appComponentFactory value=(androidx.core.app.CoreComponentFactory) from AndroidManifest.xml:24:18-86 is also present at AndroidManifest.xml:22:18-91 value=(android.support.v4.app.CoreComponentFactory). Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:26:5-186:19 to override. assistingAgriculture.app main manifest (this file), line 23
解决方案
点击App下的gradle.properties
→
\rightarrow
→添加
android.enableJetifier=true`
→
\rightarrow
→Sync Now
具体操作步骤如下图:
产生原因
问题产生的根本原因是在项目的AndroidManifest.xml
文件中存在重复的属性定义,特别是针对application@appComponentFactory
属性。具体错误信息中指出了这个问题:
Error: Attribute application@appComponentFactory value=(androidx.core.app.CoreComponentFactory) from AndroidManifest.xml:24:18-86 is also present at AndroidManifest.xml:22:18-91 value=(android.support.v4.app.CoreComponentFactory).
这意味着在AndroidManifest.xml
文件的两个地方都定义了application@appComponentFactory
属性,一个使用了androidx.core.app.CoreComponentFactory
值,另一个使用了android.support.v4.app.CoreComponentFactory
值。这种情况下,编译器无法确定该使用哪个值,导致了合并失败。
解决原因
解决方案中提到的android.enableJetifier=true
是为了确保项目中的第三方库也能够迁移到AndroidX,以便与AndroidX兼容。Jetifier工具可以自动地将第三方库中使用的旧版Support库转换为对应的AndroidX库,从而确保整个项目都在AndroidX环境下运行。因此,启用Jetifier工具有助于解决因为第三方库未迁移到AndroidX而导致的冲突问题。
参考文献
Manifest merger failed : Attribute application@appComponentFactory - Androidx
产生原因与解释原因部分 部分内容参考chatgpt
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈