Error:Execution failed for task ‘:app:transformDexArchiveWithExternalLibsDexMergerForDebug’.

java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

我再贴一张图!

Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'

被这个错误搞疯了,搞了两天!…必须写一篇文章祭奠一下

虐心之旅开始
网上各种方式
一 在app 的build.gradle下面配置
defaultConfig {
multiDexEnabled true
}
同时需要配置
dependencies{
implementation ‘com.android.support:multidex:1.0.1’
}

不过这个方式是在代码编译成.dex超过65535长度限制的时候使用的,这里行不通


二.是通过Goovy语音强制解决compile冲突问题 
先打印出来依赖冲突的版本,然后再强制指定需要的版本

configurations.all {
resolutionStrategy {
    force 'com.android.support:multidex:1.0.3'
    force 'com.android.support:support-annotations:26.1.0'
    force 'com.android.support:support-v4:26.1.0'
 
}

}
configurations.all {//打印依赖冲突版本
resolutionStrategy {
failOnVersionConflict()
}
}

三.翻墙找,老外遇到这个问题的人也不少
https://stackoverflow.com/questions/47079113/android-studio-3-0-execution-failed-for-task-unable-to-merge-dex#

以上方式,皆卒

最后…
emm…大招来了

Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'
1.在Gradle Console中 查看具体问题
2.配置打印gradle具体错误 如下图
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'
3.点击 Run with --info(上上张图的蓝色地方)
然后会获取具体错误信息
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'
蓝色部分就是具体信息…

4.然后运行 Terminal
输入 gradle app:dependencies
获取gradle 的依赖结构
这个有个小插曲,首先要进入你当前的项目,然后再输入 gradle app:dependencies
如下图所示
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'

然后搜索之前Gradle报的错误信息的依赖库
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'
查找出在那个依赖产生的(如下图)

Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'

最后,解决冲突Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'

我写的比较粗糙,可以看着一篇文章…不过这一篇缺少最后解决的方式
https://blog.csdn.net/u012214003/article/details/79632675

哎~难受啊,马飞!

相关文章: