首页 > 解决方案 > .DexArchiveMergerException:无法合并 dex

问题描述

通过android studio开发android系统应用环境。

  1. 将/target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes.jar复制到app/libs。重命名framework.jar

  2. 添加 provided fileTree(dir: 'libs', include: ['*.jar'])build.gradle

  3. 添加options.compilerArgs << '-Xbootclasspath/p:app\\libs\\framework.jar'

重建项目时,发生错误

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

    apply plugin: 'com.android.application'
android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.example.systemapplication"
        minSdkVersion 26
        targetSdkVersion 26
        multidexEnabled true
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner 
"android.support.test.runner.AndroidJUnitRunner"
        externalNativeBuild {
            cmake {
                cppFlags ""
            }
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 
'proguard-rules.pro'
    }
    }
    externalNativeBuild {
        cmake {
            path "CMakeLists.txt"
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    provided fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-
core:3.0.2'
}

Error:(6, 1) A problem occurred evaluating project ':app'.
> Could not find method multidexEnabled() for arguments [true] on 
DefaultConfig_Decorated{name=main, 

标签: androidandroid-studio

解决方案


此错误app:transformDexArchiveWithExternalLibsDexMergerForDebug通常是由于添加了可能与您的compileSdkVerison.

在您的项目中启用 Multidex。要启用它打开build.gradle(Module:app)文件,然后在defaultConfig块中写入multidexEnabled true

现在,清理并重建您的项目。


推荐阅读