錯誤提示:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
思路一:
clean+rebuild
簡單粗暴,能解決AS“發病”問題。
思路二:
在app 的build.gradle文件
defaultConfig{
...
multiDexEnabled true
}
方法數超過65535解決方案,具體添加方法請自行解決
思路三:
因爲添加相同的包依賴,或者第三方的開源庫中已經添加了某個你添加過得依賴庫,導致衝突,可以在module的build.gradle文件添加這樣一段代碼(說明看註釋):
configurations.all {
//循環一個個的依賴庫
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
//獲取當前循環到的依賴庫
def requested = details.requested
//如果這個依賴庫羣組的名字是com.android.support
if (requested.group == 'com.android.support') {
//且其名字不是以multidex開頭的
if (!requested.name.startsWith("multidex")) {
//這裏指定需要統一的依賴版本
details.useVersion '28.0.0'
}
}
}
}
說直白就是刪除重複添加的依賴,保持版本一致性
希望可以幫到您~~