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

时间:2017-12-12 18:29:23

标签: android android-studio kotlin google-play-services build.gradle

我的项目在Android Studio 3.0.1上的Kotlin中 这是我的设计格斗

buildscript {
    ext.kotlin_version = '1.2.0'
    ext.anko_version='0.10.3'
    repositories {
        jcenter()
        mavenCentral()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath 'com.google.gms:google-services:3.1.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
allprojects {
    repositories {
        google()
        jcenter()
        mavenCentral()
    }
}
task clean(type: Delete) {
    delete rootProject.buildDir
}

在这个应用程序中,我创建了一个库,在这个库中我有以下渐变文件。

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'


android {
    compileSdkVersion 26
    buildToolsVersion '26.0.2'

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }

    buildTypes {
        release {
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

}


dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation('com.google.api-client:google-api-client-android:1.22.0') {
        exclude group: 'org.apache.httpcomponents'
        exclude group: 'com.google.code.findbugs'
    }
    implementation('com.google.apis:google-api-services-gmail:v1-rev66-1.22.0') {
        exclude group: 'org.apache.httpcomponents'
    }

    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.android.support:design:26.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'

    testImplementation 'com.greghaskins:spectrum:1.2.0'

    implementation 'com.squareup.retrofit2:retrofit:2.3.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
    implementation 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'
    implementation 'com.google.code.gson:gson:2.8.0'
    implementation 'io.reactivex.rxjava2:rxjava:2.0.2'
    implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'

    implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
    implementation "org.jetbrains.anko:anko-commons:$anko_version"
    implementation 'com.android.support:multidex:1.0.2'

    implementation 'com.google.android.gms:play-services-location:11.6.2'
    implementation 'com.google.android.gms:play-services-gcm:11.6.2'
    implementation 'com.google.android.gms:play-services-auth:11.6.2'

}

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

到目前为止,项目正常编译,但是当我进行构建时,在我的手机上通过usb运行应用程序会发生以下错误,我仍然无法解决。

  

错误:任务':app的执行失败:   transformDexArchiveWithExternalLibsDexMergerForDebug'

     
    

java.lang.RuntimeException:java.lang.RuntimeException:com.android.builder.dexing.DexArchiveMergerException:无法合并     DEX

  

提前感谢您的帮助。

2 个答案:

答案 0 :(得分:0)

当我遇到这种情况时,我会注释掉multiDexEnabled true然后执行清理/构建/运行。

如果您的应用程序未达到65k方法限制,则无需启用multidex

答案 1 :(得分:0)

有同样的问题,我用两个技巧解决了这个问题 如果您已启用multiDex,请尝试从kotlin中排除注释包

implementation ("org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"){
  exclude group: 'org.jetbrains', module: 'annotations'
}

这是解决方案帮助我