com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

因项目需要引入了第三方包,发现报错

Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

很头大,各种方式都尝试了。

虽然知道本质上是jar包冲突,但是需要找到具体哪个。

解决方式

1

在app: build.gradle中修改配置

android {
    defaultConfig {
	    ...
        multiDexEnabled true
    }
    dexOptions {
        incremental true
    }
}
dependencies {
    ...
    compile 'com.android.support:multidex:1.0.3'
}

继承MultiDexApplication 或者在Application的attachBaseContext方法中加入

MultiDex.install(this);

2

在app: build.gradle中最下面添加

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            if (!requested.name.startsWith("multidex") && !requested.name.startsWith("multidex-instrumentation")) {
                details.useVersion '你自己的版本' //
            }
        }
    }
}

3

查看自己引入的第三方包使用的sdk版本,是否和自己冲突。
如果第三方是AndroidX. 你需要修改为

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
//    implementation 'com.android.support:appcompat-v7:28.0.0' //去除自己的引用包,同时修改自己的Activity等引用
}

我的情况是第三种方式解决的。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值