ERROR: Manifest merger failed

2019-10-19  本文已影响0人  王魔王

Android项目编译时碰到的异常,而我们查看日志的话显示如下

ERROR: Manifest merger failed : Attribute application@appComponentFactory value=(androidx.core.app.CoreComponentFactory) from [androidx.core:core:1.1.0] AndroidManifest.xml:24:18-86
    is also present at [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91 value=(android.support.v4.app.CoreComponentFactory).
    Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:5:5-19:19 to override.

下面是AndroidStudio的日志截图

AndroidStudio的日志显示
编译异常通常比较难搞,这是因为我们对Gradle掌握的太少的缘故,不过这并不影响我们排错。
出了错首先就是要看日志,日志通常能解决我们90%的问题,剩下的10%我们多看几遍多碰到几遍也能记住【手动微笑】
我们来仔细看日志
ERROR: Manifest merger failed :Attribute application@appComponentFactory value=(androidx.core.app.CoreComponentFactory) from[androidx.core:core:1.1.0] AndroidManifest.xml:24:18-86
is also present at [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91 value=(android.support.v4.app.CoreComponentFactory).

Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:5:5-19:19 to override.
日志的开头说:
ERROR: Manifest merger failed,翻译过来就是清单文件合并失败了,千万不要看到这里就去检查清单文件,接着往下看,当你看到xxx is alos present at xxx的时候,你应该明白是包冲突了
发生冲突的包就是 is also present at 前后描述的两个包
从Suggestion开始的就是ide自动提示给我们的解决方案,而这个推荐的解决方案,很多时候都并不够准确

解决方案

仔细看日志中发生冲突的两个包,删掉自己不想使用的那一个

一般发生包冲突都是我们导入了相同的包,在Android开发中,导入包的操作通常有:

上一篇下一篇

猜你喜欢

热点阅读