【问题标题】:Unable to merge dex still appear after enabling multiDex开启multiDex后依然出现Unable to merge dex
【发布时间】:2018-02-05 13:31:59
【问题描述】:

我找到的所有解决方案都启用了 multiDex 我试过但没有用 另一种解决方案是启用它并添加 compile 'com.android.support:multidex:1.0.2' 但也没有用

摇篮:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "recipe.bakes.bakesrecipe"
        minSdkVersion 21
        targetSdkVersion 26
        multiDexEnabled true
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.android.support:support-v4: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'
    compile 'com.android.support:support-fragment:26.1.0'
    compile 'com.android.support:cardview-v7:26.1.0'
    compile 'com.android.support:recyclerview-v7:26.1.0'
    implementation 'com.android.support:appcompat-v7:26.1.0'
    compile 'com.android.volley:volley:1.1.0'
    compile 'com.google.code.gson:gson:2.8.2'
    compile 'com.android.support:multidex:1.0.2'
    implementation files('libs/gson-2.8.2.jar'

)
}

错误:任务 ':app:transformDexArchiveWithExternalLibsDexMergerForDebug' 执行失败。 java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: 无法合并 dex

【问题讨论】:

    标签: java android android-studio android-gradle-plugin dex


    【解决方案1】:

    不要为您的项目使用多个相同的依赖项。您只需要使用其中一个 gson。

    libs 目录和 build.gradle 依赖项中删除 gson jar。你的依赖块应该是这样的:

    dependencies {
        implementation fileTree(include: ['*.jar'], dir: 'libs')
        ...
        implementation 'com.google.code.gson:gson:2.8.2'
        //implementation files('libs/gson-2.8.2.jar')
    }
    

    对于您当前的依赖项块,您实际上并不需要 multidex。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多