在安卓开发中肯定会使用到第三方库,gradle提供了一种快捷的依赖方式,但在开发中遇到了下面这种情况我们要怎么解决呢?
Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
错误
这个错误是指你的项目中存在两个相同的依赖库,在我项目中遇到的是:
compile'com.allenliu.versionchecklib:library:2.0.3' 和
implementation'com.android.support:appcompat-v7:26.1.0' 产生了冲突。
即versionchecklib:library这个库已经依赖了com.android.support,就等于你项目中存在两个com.android.support库。
解决办法:使用gradle的exclue排除某些库。
栗子:api ("com.allenliu.versionchecklib:library:2.0.3") {
exclude group:'com.android.support'
}
问题解决。