0

I got this error when i have tried to rebuild my project:

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

Despite i have added this line

multiDexEnabled true

in my app module gradle file, the error become as below.

Error:Execution failed for task ':app:transformClassesWithMultidexlistForDebug'.
> java.io.IOException: Can't write [C:\Users\Amine\AndroidStudioProjects\Movies\app\build\intermediates\multi-dex\debug\componentClasses.jar] (Can't read [C:\Users\Amine\AndroidStudioProjects\Movies\app\build\intermediates\transforms\desugar\debug\19.jar(;;;;;;**.class)] (Duplicate zip entry [19.jar:android/support/design/widget/CoordinatorLayout$Behavior.class]))

Also I have cleaned after rebuilded the project, but I have the same issue.

Below , the gradle of my app module:

apply plugin: 'com.android.application'
android {
    compileSdkVersion 27
    buildToolsVersion '27.0.0'
    defaultConfig {
        applicationId "com.aoutir.mohamed.movies"
        minSdkVersion 16
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    buildTypes.each {
        it.buildConfigField("String", "MOVIES_END_POINT", "\"https://api.themoviedb.org\"")
        it.buildConfigField("String", "APPIKEY", "\my API Key")
    }
    compileOptions {
        targetCompatibility JavaVersion.VERSION_1_8
        sourceCompatibility JavaVersion.VERSION_1_8
    }
}
dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:recyclerview-v7:27.0.0'
    compile 'com.android.support:cardview-v7:27.0.0'
    compile 'com.squareup.retrofit2:retrofit:2.1.0'
    compile 'com.squareup.retrofit2:converter-gson:2.1.0'
    compile 'com.squareup.okhttp3:okhttp:3.0.1'
    compile 'io.reactivex.rxjava2:rxjava:2.0.1'
    compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'
    compile 'com.android.support:appcompat-v7:27.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.android.support:support-v4:27.+'
    compile 'com.android.support:design:27.0.1'
    testCompile 'junit:junit:4.12'
}

Below the gradle file of my project module:

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'

    }
}

allprojects {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
        google()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Thanks in advance for any help.

Mohamed Aoutir
  • 613
  • 3
  • 11
  • 22
  • **Duplicate zip entry** Follow https://stackoverflow.com/a/21100040/4168607 – ADM Mar 24 '18 at 15:10
  • @ADM I followed the post, but when run the command gradle -q dependencies, i don't found any line that indicates missing library – Mohamed Aoutir Mar 24 '18 at 16:01

1 Answers1

0

This is because you have duplicated support library. The source of the problem is the + usage for version. You should not use this:

compile 'com.android.support:appcompat-v7:27.+'
compile 'com.android.support:support-v4:27.+'

because gradle will use the latest version of 27 which is 27.1.0 (Take a look at Recent Support Library Revisions). Then your dependencies block will be something like this:

dependencies {
    //...

    compile 'com.android.support:recyclerview-v7:27.0.0'
    compile 'com.android.support:cardview-v7:27.0.0'

    //...

    compile 'com.android.support:appcompat-v7:27.1.0'
    compile 'com.android.support:support-v4:27.27.1.0'
}

which is a totally different version.

But wait, you also use the following:

compile 'com.android.support:design:27.0.1'

which is a different version again. The real problem is this, support design library is implicitly using appcompat-v7 and support-v4 library. So, the above line is the same as this:

compile 'com.android.support:design:27.0.1'
compile 'com.android.support:appcompat-v7:27.0.1'
compile 'com.android.support:support-v4:27.0.1'

The solutions for your problem is, you need to use same version of support library. Something like this:

dependencies {

    compile 'com.android.support:recyclerview-v7:27.1.0'
    compile 'com.android.support:cardview-v7:27.1.0'
    compile 'com.android.support:design:27.1.0'
    // adding appcompat-v7 and support-v4 is not necessary 
    //when using support design.

   // ...
}
ישו אוהב אותך
  • 28,609
  • 11
  • 78
  • 96