Search code examples
javaandroidandroid-studioandroid-gradle-plugindex

Unable to merge dex still appear after enabling multiDex


All solutions i found were enable multiDex i tried it but didn't work another solution was enable it and add compile 'com.android.support:multidex:1.0.2' but didn't work too

The 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'

)
}

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


Solution

  • Don't use multiple same dependency for your project. You need to use only one of gson.

    Remove the gson jar from your libs directory and from build.gradle dependencies. Your dependencies block should be something like this:

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

    For your current dependencies block, you don't really need multidex.