.DexArchiveMergerException:无法合并dex

时间:2018-07-26 05:24:51

标签: android android-studio

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

  1. out / 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, 

1 个答案:

答案 0 :(得分:0)

此错误compileSdkVerison通常是由于添加了可能与您的build.gradle(Module:app)不兼容的外部库而发生的。

在项目中启用Multidex。要启用它,请打开defaultConfig文件,然后在class_method_message块中写 multidexEnabled true

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