【问题标题】:Unable to merge dex无法合并 dex
【发布时间】:2018-02-26 07:14:35
【问题描述】:

我有 Android Studio 测试版。我创建了一个新项目并编译了我的旧模块,但是当我尝试启动应用程序时,它没有启动并显示以下消息:

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

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

但我不知道如何解决这个错误。我用谷歌搜索了几个小时,但没有成功。

我的项目毕业:

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

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0-beta6'
        classpath "io.realm:realm-gradle-plugin:3.7.1"
        classpath 'com.google.gms:google-services:3.1.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

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

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

我的应用分级:

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"
    defaultConfig {
        applicationId "parad0x.sk.onlyforyou"
        minSdkVersion 21
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
        }
    }
    compileOptions {
        targetCompatibility 1.7
        sourceCompatibility 1.7
    }
    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
    }
    lintOptions {
        checkReleaseBuilds false
    }
    productFlavors {
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    //noinspection GradleCompatible
    compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
    compile project(path: ':loginregisterview')


}

还有我的模块 gradle:

    apply plugin: 'com.android.library'
apply plugin: 'realm-android'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"

    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

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

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    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:26.0.2'
    compile 'com.android.support:support-v4:26.1.0'
    compile 'com.github.bumptech.glide:glide:4.0.0'
    testCompile 'junit:junit:4.12'
    compile project(path: ':parser')

}

我的第二个模块:

     apply plugin: 'com.android.library'
apply plugin: 'realm-android'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"
    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }

    realm {
        syncEnabled = true
    }
    useLibrary 'org.apache.http.legacy'

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

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile 'junit:junit:4.12'
    //  compile 'com.android.support:appcompat-v7:23.1.0'

    //   compile 'com.fasterxml.jackson.core:jackson-core:2.9.0'
 //   compile 'com.fasterxml.jackson.core:jackson-annotations:2.9.0'
 //   compile 'com.fasterxml.jackson.core:jackson-databind:2.9.0'
    compile 'com.google.code.gson:gson:2.6.2'
}

____________发现_________

当我没有导入第二个模块(解析器)时,应用程序没有在 dex 上崩溃,但是当没有导入模块时,应用程序不起作用。 :D :D

【问题讨论】:

  • 如果有人在 Android Studio 3.0 稳定版中遇到同样的问题,我强烈建议您查看答案stackoverflow.com/questions/46949761/…,看看它是否可以帮助您。
  • 我遇到了同样的问题,我遵循了这个页面上提到的所有方法,但没有帮助我,所以我去 gradle 并在每个库上按住光标以检查他们的新版本是否可用或不。那些有新版本的人,所以我更新了,同步 gradle 并运行。它奏效了。

标签: android dex android-studio-3.0


【解决方案1】:

在关注依赖关系之前尝试了所有这些。

下面的杀手锏:

//implementation 'org.apache.httpcomponents:httpcore:4.3.1'
//implementation 'org.apache.httpcomponents:httpmime:4.3.1'

现在正在按预期工作。

【讨论】:

  • 这可能应该是对@Mansour 答案的评论重复的引用将使其失败。这种回应本身并没有为这个问题提供新的见解。 OP 已经接受了此线程上的答案,因此请确保您的答案解释了为什么它与其他答案不同,并且具有类似的高质量,并带有参考材料的链接和深入的解释。这个问题的其他一些答案是结构良好且被引用的帖子的很好例子。
【解决方案2】:

如果你正在使用

compile ("org.apache.oltu.oauth2:org.apache.oltu.oauth2.client:1.0.1")

你应该改成

compile ("org.apache.oltu.oauth2:org.apache.oltu.oauth2.client:1.0.1"){
    exclude group:'org.apache.oltu.oauth2' , module: 'org.apache.oltu.oauth2.common'
}

由于客户端库已经包含公共库,它会创建一个重复的类条目,这会导致错误:

无法合并dex

【讨论】:

    猜你喜欢
    • 2018-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-05
    • 2018-04-28
    • 1970-01-01
    相关资源
    最近更新 更多