无法合并dex在启用multiDex后仍会出现

问题描述 投票:0回答:1

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

Gradle:

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 dex
1个回答
0
投票

不要对项目使用多个相同的依赖项。你只需要使用一个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。

© www.soinside.com 2019 - 2024. All rights reserved.