依赖性问题:DexArchiveMergerException

时间:2018-06-07 07:35:26

标签: android exception multidex android-multidex

我创建了一个包含以下依赖项的新项目:

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:design:26.1.0'

implementation 'com.github.bumptech.glide:glide:4.7.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'
implementation 'com.squareup.okhttp:okhttp:2.6.0'
implementation 'com.google.code.gson:gson:2.8.2'
}

在运行应用时,我遇到错误:

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

可能是什么问题?

1 个答案:

答案 0 :(得分:1)

Jaimin,希望您使用..

在app gradle文件中启用了multidex
multiDexEnabled true

如果仍未解决,请添加以下代码:

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '26.+'
            }
        }
    }
}