android - 运行应用程序失败,错误'com.android.builder.dexing.DexArchiveMergerException:无法合并dex' [英] android - Running app fails with error 'com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex'

查看:3758
本文介绍了android - 运行应用程序失败,错误'com.android.builder.dexing.DexArchiveMergerException:无法合并dex'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的手机上运行我的应用程序,但在 build 时间失败,出现以下错误:

 任务':app:transformDexArchiveWithExternalLibsDexMergerForDebug'的执行失败。 




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


尝试到目前为止,但无济于事:
- >清理和重建(重建失败)
- >删除 ./ gradle 文件和所有项目构建和缓存文件,然后缓存失效



我的项目gradle文件:

  //顶级构建文件,您可以在其中添加对所有子项目/模块通用的配置选项。 
$ b buildscript {
ext.kotlin_version ='1.1.51'
repositories {
jcenter()
google()
mavenCentral()
}
依赖项{
classpath'com.android.tools.build:gradle:3.0.0-beta6'

//注意:不要放置您的应用程序依赖关系在这里;它们属于单个模块build.gradle文件中的
//
classpathorg.jetbrains.kotlin:kotlin-gradle-plugin:$ kotlin_version
}
}

allprojects {
存储库{
jcenter()
google()
mavenCentral()
}
}

任务清理(类型:删除){
删除rootProject.buildDir
}

我的应用Gradle文件:

  apply plugin:'com.android.application'
apply plugin:'kotlin -android'
apply plugin:'kotlin-kapt'
apply plugin:'kotlin-android-extensions'

def daggerVersion ='2.11'

android {
compileSdkVersion 25
buildToolsVersion26.0.2
defaultConfig {
applicationIdcom.connectus.connectus
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName1.0
testInstrum entationRunnerandroid.support.test.runner.AndroidJUnitRunner
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt') ,'proguard-rules.pro'
}
}
packagingOptions {
不包括'META-INF / INDEX.LIST'
}
}

kapt {
generateStubs = true
}

依赖关系{
/ **
* Kotlin
* /
编译org.jetbrains.kotlin:kotlin-stdlib:$ kotlin_version
compile'org.jetbrains.anko:anko-support-v4:0.10.1'

/ * *
*单元测试
* /
testCompile'junit:junit:4.12'
testCompile'org.mockito:mockito-core:1.10.19'
testCompile' org.powermock:powermock-module-junit4:1.6.2'
testCompile'org.powermock:powermock-api-mockito:1.6.2'

/ **
* Android视图和窗口ts
* /
compile'c​​om.android.support:appcompat-v7:25.3.1'
compile'c​​om.android.support:recyclerview-v7:25.3.1'
编译'com.android.support:cardview-v7:25.3.1'

/ **
*翻新
* /
编译'com.squareup。 retrofit2:retrofit:2. +'
compile'c​​om.squareup.retrofit2:converter-gson:2. +'
compile'c​​om.squareup.retrofit2:adapter-rxjava:2. +'
编译'io.reactivex:rxjava:1.0.4'
编译'io.reactivex:rxandroid:0.24.0'

/ **
* Glide
* /
compile'c​​om.github.bumptech.glide:glide:3.7.0'

/ **
* Dagger 2
* /
kaptcom.google.dagger:dagger-compiler:$ daggerVersion
compilecom.google.dagger:dagger:$ daggerVersion
provided'org.glassfish:javax.annotation:10.0-b28 '

/ **
*用于视图注入的Butterknife
* /
compile'c​​o m.jakewharton:butterknife:8.8.1'
kapt'com.jakewharton:butterknife-compiler:8.8.1'

/ **
* GSON
* /
compile'c​​om.google.code.gson:gson:2.6.2'
compile'org.powermock:powermock-api-mockito:1.6.2'

/ **
* Facebook SDK
* /
编译'com.facebook.android:facebook-login:[4,5)'

/ **
* UI测试
* /
androidTestCompile'c​​om.android.support:support-annotations:25.3.1'
androidTestCompile'junit:junit:4.12'

testCompile'c​​om.google.dexmaker:dexmaker:1.2'
testCompile'c​​om.google.dexmaker:dexmaker-mockito:1.2'
androidTestCompile('com.android.support.test.espresso:espresso- core:2.2.2'){
exclude module:'support-annotations'
}
androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.2' ){
排除模块:'支持-annotations'
排除模块:'appcompat-v7'
排除模块:'support-v4'
排除模块:'support-v13'
排除模块:'recyclerview-v7 '
exclude module:'design'
}
androidTestCompile('com.android.support.test:runner:0.3'){
排除模块:'support-annotations'

androidTestCompile('com.android.support.test:rules:0.3'){
exclude module:'support-annotations'
}
compileorg。 jetbrains.kotlin:kotlin-stdlib-jre7:$ kotlin_version
implementationcom.android.support.constraint:constraint-layout:1.0.2'
}

apply plugin :'kotlin-android'
apply plugin:'kotlin-android-extensions'
repositories {
mavenCentral()
}

我正在使用Kotlin和Android Studio 3.0.0 beta 6.问题是什么?

解决方

虽然我不完全确定这个原因,但看起来,在完成一些挖掘,jetotins在kotlin插件和其他地方包含的注释库之间存在版本冲突。您可以运行

gradle:app:assembleDebug --stacktrace



在最后给出

 引起:com.android.dex.DexException:Multiple dex文件定义了Lorg / intellij / lang / annotations / JdkConstants $ PatternFlags; 
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:661)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:616)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:598)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
at com.android .dx.merge.DexMerger.merge(DexMerger.java:198)
at com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:61)
... 1 more

我通过从kotlin依赖关系中排除注释库来解决此问题。 (可能需要清理和重建)

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

这适用于我,但我不确定这个解决方案有多好。


I am trying to run my application on my phone but during build time it fails with the following error:

Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.

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

What I tried so far, but to no avail: -> Clean and rebuild (fails on rebuild) -> Remove ./gradle file and all project build and cache files, then cache invalidation

My project gradle file:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext.kotlin_version = '1.1.51'
    repositories {
        jcenter()
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0-beta6'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        jcenter()
        google()
        mavenCentral()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

My app Gradle file:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'

def daggerVersion = '2.11'

android {
    compileSdkVersion 25
    buildToolsVersion "26.0.2"
    defaultConfig {
        applicationId "com.connectus.connectus"
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/INDEX.LIST'
    }
}

kapt {
    generateStubs = true
}

dependencies {
    /**
     * Kotlin
     */
    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    compile 'org.jetbrains.anko:anko-support-v4:0.10.1'

    /**
     * Unit testing
     */
    testCompile 'junit:junit:4.12'
    testCompile 'org.mockito:mockito-core:1.10.19'
    testCompile 'org.powermock:powermock-module-junit4:1.6.2'
    testCompile 'org.powermock:powermock-api-mockito:1.6.2'

    /**
     * Android views and widgets
     */
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support:recyclerview-v7:25.3.1'
    compile 'com.android.support:cardview-v7:25.3.1'

    /**
     * Retrofit
     */
    compile 'com.squareup.retrofit2:retrofit:2.+'
    compile 'com.squareup.retrofit2:converter-gson:2.+'
    compile 'com.squareup.retrofit2:adapter-rxjava:2.+'
    compile 'io.reactivex:rxjava:1.0.4'
    compile 'io.reactivex:rxandroid:0.24.0'

    /**
     * Glide
     */
    compile 'com.github.bumptech.glide:glide:3.7.0'

    /**
     * Dagger 2
     */
    kapt "com.google.dagger:dagger-compiler:$daggerVersion"
    compile "com.google.dagger:dagger:$daggerVersion"
    provided 'org.glassfish:javax.annotation:10.0-b28'

    /**
     * Butterknife for view injection
     */
    compile 'com.jakewharton:butterknife:8.8.1'
    kapt 'com.jakewharton:butterknife-compiler:8.8.1'

    /**
     * GSON
     */
    compile 'com.google.code.gson:gson:2.6.2'
    compile 'org.powermock:powermock-api-mockito:1.6.2'

    /**
     * Facebook SDK
     */
    compile 'com.facebook.android:facebook-login:[4,5)'

    /**
     * UI Testing
     */
    androidTestCompile 'com.android.support:support-annotations:25.3.1'
    androidTestCompile 'junit:junit:4.12'

    testCompile 'com.google.dexmaker:dexmaker:1.2'
    testCompile 'com.google.dexmaker:dexmaker-mockito:1.2'
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2') {
        exclude module: 'support-annotations'
    }
    androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.2') {
        exclude module: 'support-annotations'
        exclude module: 'appcompat-v7'
        exclude module: 'support-v4'
        exclude module: 'support-v13'
        exclude module: 'recyclerview-v7'
        exclude module: 'design'
    }
    androidTestCompile('com.android.support.test:runner:0.3') {
        exclude module: 'support-annotations'
    }
    androidTestCompile('com.android.support.test:rules:0.3') {
        exclude module: 'support-annotations'
    }
    compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
}

apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
repositories {
    mavenCentral()
}

I am using Kotlin and Android Studio 3.0.0 beta 6. What is the problem?

解决方案

Although I am not completely sure about the cause for this, it seems, after doing some digging, that there is a version clash between the annotation libraries included by jetbrains in the kotlin plugin and somewhere else. You can verify this by running

gradle :app:assembleDebug --stacktrace

which gives, at the end,

Caused by: com.android.dex.DexException: Multiple dex files define Lorg/intellij/lang/annotations/JdkConstants$PatternFlags;
    at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:661)
    at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:616)
    at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:598)
    at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
    at com.android.dx.merge.DexMerger.merge(DexMerger.java:198)
    at com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:61)
    ... 1 more

I solved this by excluding the annotations library from kotlin dependency. (Clean and rebuild might be needed after this)

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

This works for me, but I am not sure about how good this solution is.

这篇关于android - 运行应用程序失败,错误'com.android.builder.dexing.DexArchiveMergerException:无法合并dex'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆