Android Studio 3.0 无法合并 dex

10

我刚将Android Studio从2.3.3更新到了3.0,现在我遇到了错误。

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

这是我的 Gradle 文件:

apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion '26.0.2'
defaultConfig {
    applicationId "d91.compassacademy"
    minSdkVersion 19
    targetSdkVersion 25
    versionCode 3
    versionName "1.0"

    testInstrumentationRunner 
"android.support.test.runner.AndroidJUnitRunner"
    vectorDrawables.useSupportLibrary = true
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
    debug {
        debuggable true
    }
}
}

repositories {
    mavenCentral()
    google()
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:multidex:1.0.2'

compile('com.google.api-client:google-api-client-android:1.22.0') {
    exclude group: 'org.apache.httpcomponents'
}
compile 'pub.devrel:easypermissions:0.2.1'
compile project(path: ':mapviewpager')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', 
{
    exclude group: 'com.android.support', module: 'support-annotations'

})
compile 'com.android.support:appcompat-v7:25.4.0'
compile 'com.android.support:recyclerview-v7:25.4.0'
compile 'com.android.support:cardview-v7:25.4.0'
compile 'com.google.firebase:firebase-database:11.4.2'
compile 'com.google.android.gms:play-services-auth:11.4.2'
compile 'com.google.android.gms:play-services-places:11.4.2'
compile 'com.google.android.gms:play-services:11.4.2'
compile 'com.google.firebase:firebase-storage:11.4.2'
compile 'com.google.firebase:firebase-auth:11.4.2'
compile 'com.firebaseui:firebase-ui-database:1.1.1'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.theartofdev.edmodo:android-image-cropper:2.3.1'
compile 'com.roughike:bottom-bar:2.1.1'
compile 'com.android.support:support-v4:25.4.0'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.android.support:support-vector-drawable:25.4.0'
compile 'pub.devrel:easypermissions:0.2.1'
compile 'com.google.code.findbugs:jsr305:2.0.1'
compile 'com.jakewharton:butterknife:8.4.0'
compile 'com.getbase:floatingactionbutton:1.10.1'
compile 'com.android.support:multidex:1.0.2'
compile 'com.android.support.constraint:constraint-layout:1.1.0-beta3'
testCompile 'junit:junit:4.12'
}


apply plugin: 'com.google.gms.google-services'

我建议您编辑问题并发布Gradle控制台的完整输出。您的具体问题(例如,重复类定义)应在该输出的其他位置报告。例如,请参见此问题 - CommonsWare
1
简单的构建->清除项目将解决问题... - Viktor Yakunin
可能是Dex错误在Android Studio 3.0 Beta4上的重复问题。 - Shaishav Jogani
请查看我的答案:https://dev59.com/0FYO5IYBdhLWcg3wTPrk#47023992希望能对您有所帮助。 - Prodigy
https://dev59.com/0FYO5IYBdhLWcg3wTPrk - Android Studio 3.0 Beta4 上的 Dex 错误 - user784625
无法合并dex - user784625
6个回答

4

我查了一下:

Error:Execution failed for task ':memDicez:transformDexArchiveWithExternalLibsDexMergerForDebug'.

com.android.builder.dexing.DexArchiveMergerException: 无法合并dex

昨天我遇到了这个问题,但是没有找到有用的信息。

现在我的问题已经解决了。

这种方法可能会帮助你找到解决方案(对我有效,但不能保证对你有效)。

我的情况是:

android {
    compileSdkVersion 25
    buildToolsVersion '26.0.2'

    defaultConfig {
        applicationId "(my secret applicationId)"
        minSdkVersion 21
        targetSdkVersion 25
        multiDexEnabled true
    }

    ...

}

并且。
dependencies {
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support:support-v4:25.3.1'
    compile 'ch.acra:acra:4.9.2'
    //compile 'com.google.android.gms:play-services-auth:9.0.0'
    compile 'com.loopj.android:android-async-http:1.4.9'
    compile 'com.koushikdutta.ion:ion:2.+'
    compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'
}

当我改变了:

        minSdkVersion 21

to

        minSdkVersion 16

我得到了更详细的错误信息,通过谷歌/堆栈溢出提供了解决方案。

在我的情况下

compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'

应该更改为

compile('com.googlecode.json-simple:json-simple:1.1.1') {
    exclude group: 'org.hamcrest', module: 'hamcrest-core'
}

您可以随时将minSdkVersion更改回更高的值,但是减少它似乎会提供更详细(或更容易被谷歌搜索到的)问题和解决方案。

祝好!

S.


1
在你的文件build.gradle(项目:XXX)中,有这段片段。
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'                
    }
}

之前版本是2.3.3,当你更新Android Studio时变成了3.0.0。尝试将其恢复为2.3.3,然后重新同步,等待Android Studio要求更新Gradle和gradle插件至3.0.0。此时,不应出现与合并Dex相关的构建问题。


0

在 "设置"-"Android SDK"-"SDK工具" 中查看,Google Play服务已被勾选并安装v.46版本。同时,请检查是否需要更新其他内容以适应新的Android版本。

清理并重新构建项目。如果问题仍然存在,您可以尝试删除".gradle"文件夹并再次清理和重新构建。

对我来说,我还需要关闭所有Android项目并重新打开Android Studio才能使其正常工作。

祝你好运!


0
在我的情况下,这是在添加了以下依赖项后开始发生的。
implementation 'com.getbase:floatingactionbutton:1.9.0'

我尝试了这里和其他地方发布的所有建议,但都没有奏效。
然后我尝试了一个在许多其他情况下都有帮助的常见解决方案。 我仅仅使用了从工具中找到的以下菜单中的“与Gradle文件同步项目”。 enter image description here

0

multiDexEnabled true

示例

android {
    compileSdkVersion 25
    buildToolsVersion '26.0.2'
    defaultConfig {
        applicationId "com.xx.xxx"
        minSdkVersion 15
        targetSdkVersion 24
        versionCode 9
        versionName "1.0"
        multiDexEnabled true //Add this
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            shrinkResources true
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    } }

0
我的问题通过将最小SDK更改为16和目标SDK更改为25,并在default.config中添加multidexenabled=true来解决。在app/build.gradle中添加以下内容:
compile 'com.android.support:appcompat-v7:25.+'
compile 'com.android.support:design:25.+'

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接