3

I started getting the below error

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

I tried to reset my backup when it was working but the same problem

I tried all the solution such as

multiDexEnabled true

cleaning and rebuilding the project, but it didn't work. Any help will be appreciated.

App file

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    buildToolsVersion '27.0.2'
    defaultConfig {
        applicationId "com.example"
        minSdkVersion 18
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
        resConfigs "auto"

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
ext {
    supportLibraryVersion = '27.0.2'
    grpcVersion = '1.4.0'
}
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
    testImplementation 'junit:junit:4.12'
//appcompat libraries
    compile 'com.android.support:design:27.0.2'
    compile 'com.android.support:appcompat-v7:27.0.2'
    implementation 'com.android.support:support-v4:27.1.0'

//butterknife
    compile 'com.jakewharton:butterknife:8.8.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'

//retrofit
    implementation 'com.squareup.retrofit2:retrofit:2.3.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
    implementation 'com.squareup.okhttp3:okhttp:3.8.0'
    implementation 'com.jakewharton.retrofit:retrofit1-okhttp3-client:1.0.2'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.scottyab:aes-crypto:0.0.4'
//circleimageview
    implementation 'de.hdodenhof:circleimageview:2.2.0'
//ZXing for barCode reader
    compile 'com.journeyapps:zxing-android-embedded:3.2.0@aar'
    compile 'com.google.zxing:core:3.2.1'
//gson
    compile 'com.google.code.gson:gson:2.8.2'
//recyclerview and cardview
    implementation 'com.android.support:cardview-v7:27.0.2'
    compile 'com.android.support:recyclerview-v7:+'
//play-services
    compile 'com.google.android.gms:play-services-maps:11.8.0'




    implementation 'com.github.bumptech.glide:glide:4.3.1'
    implementation 'com.jaeger.statusbarutil:library:1.4.0'
    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-annotations:27.0.2'
    compile 'com.wang.avi:library:2.1.3'

}

Project file

buildscript {

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

    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

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

I had looked at many other questions and answers on here but cannot seem to find a solution that will rectify the problem :(

Ayman
  • 183
  • 1
  • 3
  • 14
  • 1
    Examine your Gradle console. There should be more details in there of exactly what went wrong. This is just the end message. See [this question](https://stackoverflow.com/q/48990598/115145) for an example. – CommonsWare Feb 28 '18 at 11:55
  • I'm just getting the error message DexArchiveMergerException: Unable to merge dex – Ayman Feb 28 '18 at 11:59
  • See [my answer](https://stackoverflow.com/a/49026135/8568479) to the similar question. Also replace deprecated `compile` by `implementation` in your gradle file – fdermishin Feb 28 '18 at 12:33
  • I already tried this solution but nothing change – Ayman Feb 28 '18 at 12:40
  • I've noticed that you declare supportLibraryVersion, which is not used anywhere. For example you can replace 'com.android.support:design:27.0.2' by 'com.android.support:design:${supportLibVersion}' and do so for all `com.android.support` libraries. In your question there are inconsistent different versions of support library. – fdermishin Feb 28 '18 at 12:50
  • I know that but I do it to make sure the problem is not from here – Ayman Feb 28 '18 at 13:01

2 Answers2

1

I have solved after try all the solutions on stackoverflow, try to do the following steps in its order

  1. Replace all compile with implementation
  2. Make all supportLibraryVersion = '27.0.2'
  3. Change

'com.google.android.gms:play-services-maps:11.8.0'

to

'com.google.android.gms:play-services-maps:11.4.0'

  1. Remove all the unused library
  2. Delete the .gradle folder inside your project
  3. Remove build folders and the gradle cache
  4. file -> invalidate caches/restart
  5. Build > Clean Project
  6. Add

dependencies { implementation 'com.android.support:multidex:1.0.1'}

  1. Add

android { defaultConfig { multiDexEnabled true } }

  1. Async project

And finally this is my App file

apply plugin: 'com.android.application'

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

}
ext {
    supportLibraryVersion = '27.0.2'

}
dependencies {

    implementation fileTree(dir: 'libs', include: ['*.jar'])
    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'

    implementation 'com.android.support:support-v4:27.0.2'
    implementation 'com.android.support:appcompat-v7:27.0.2'
    implementation 'com.android.support:design:27.0.2'


//constraint
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'

//butterknife
    implementation  'com.jakewharton:butterknife:8.8.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
//avi:library
    implementation  'com.wang.avi:library:2.1.3'

//circleimageview
    implementation 'de.hdodenhof:circleimageview:2.2.0'

//retrofit2
    implementation 'com.squareup.retrofit2:retrofit:2.3.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
    implementation 'com.squareup.okhttp3:okhttp:3.8.0'
    implementation 'com.jakewharton.retrofit:retrofit1-okhttp3-client:1.0.2'


//recyclerview and cardview
    implementation  'com.android.support:recyclerview-v7:27.0.2'
    implementation 'com.android.support:cardview-v7:27.0.2'


//ZXing for barCode reader
    implementation  'com.journeyapps:zxing-android-embedded:3.2.0@aar'
    implementation  'com.google.zxing:core:3.2.1'

//play-services
    implementation  'com.google.android.gms:play-services-maps:11.4.0'

//gson
    implementation  'com.google.code.gson:gson:2.8.2'
//statusbarutil
    implementation  'com.jaeger.statusbarutil:library:1.4.0'
//glide
    implementation 'com.github.bumptech.glide:glide:4.6.1'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.6.1'
//multidex
    implementation 'com.android.support:multidex:1.0.1'
}

ِِActually I didn't understand the real reason about it and why that happened suddenly

So if anyone know that please tell me with full details

I hope this will help you

Ayman
  • 183
  • 1
  • 3
  • 14
  • for me It happened because of pagging library. They have moved some classes from library to native recylerview-v7 package, So I got the same exception , I had to update support libs version to `27.1.0`(latest) and also pagging library to `alpha6` – AJay Mar 01 '18 at 02:43
-1

this worked for me after couple of hours wasting time

just do this

Implementation >>> annotationProcessor

Namini40
  • 100
  • 7