10

Just Updated android studio from 2.3.3 to 3.0 now I am having the error

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

Here is my gradle file:

apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion '26.0.2'
defaultConfig {
    applicationId "d91.compassacademy"
    minSdkVersion 19
    targetSdkVersion 25
    versionCode 3
    versionName "1.0"

    testInstrumentationRunner 
"android.support.test.runner.AndroidJUnitRunner"
    vectorDrawables.useSupportLibrary = true
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
    debug {
        debuggable true
    }
}
}

repositories {
    mavenCentral()
    google()
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:multidex:1.0.2'

compile('com.google.api-client:google-api-client-android:1.22.0') {
    exclude group: 'org.apache.httpcomponents'
}
compile 'pub.devrel:easypermissions:0.2.1'
compile project(path: ':mapviewpager')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', 
{
    exclude group: 'com.android.support', module: 'support-annotations'

})
compile 'com.android.support:appcompat-v7:25.4.0'
compile 'com.android.support:recyclerview-v7:25.4.0'
compile 'com.android.support:cardview-v7:25.4.0'
compile 'com.google.firebase:firebase-database:11.4.2'
compile 'com.google.android.gms:play-services-auth:11.4.2'
compile 'com.google.android.gms:play-services-places:11.4.2'
compile 'com.google.android.gms:play-services:11.4.2'
compile 'com.google.firebase:firebase-storage:11.4.2'
compile 'com.google.firebase:firebase-auth:11.4.2'
compile 'com.firebaseui:firebase-ui-database:1.1.1'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.theartofdev.edmodo:android-image-cropper:2.3.1'
compile 'com.roughike:bottom-bar:2.1.1'
compile 'com.android.support:support-v4:25.4.0'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.android.support:support-vector-drawable:25.4.0'
compile 'pub.devrel:easypermissions:0.2.1'
compile 'com.google.code.findbugs:jsr305:2.0.1'
compile 'com.jakewharton:butterknife:8.4.0'
compile 'com.getbase:floatingactionbutton:1.10.1'
compile 'com.android.support:multidex:1.0.2'
compile 'com.android.support.constraint:constraint-layout:1.1.0-beta3'
testCompile 'junit:junit:4.12'
}


apply plugin: 'com.google.gms.google-services'
Sneh Pandya
  • 8,197
  • 7
  • 35
  • 50
Cody Kolbert
  • 101
  • 1
  • 1
  • 3
  • I suggest that you edit the question and post the entire output of your Gradle console. Your specific problem (e.g., duplicate class definition) should be reported elsewhere in that output. For example, see [this question](https://stackoverflow.com/q/46978913/115145). – CommonsWare Oct 27 '17 at 18:02
  • 1
    simple build->clear project will solve the issue... – Viktor Yakunin Oct 27 '17 at 20:04
  • Possible duplicate of [Dex error On Android Studio 3.0 Beta4](https://stackoverflow.com/questions/46053902/dex-error-on-android-studio-3-0-beta4) – Shaishav Jogani Oct 27 '17 at 23:57
  • Check my answer here: https://stackoverflow.com/a/47023992/4159105 Hope it helps – Prodigy Oct 30 '17 at 23:32
  • https://stackoverflow.com/questions/46053902/dex-error-on-android-studio-3-0-beta4 - Dex error On Android Studio 3.0 Beta4 – user784625 Oct 31 '17 at 11:54
  • https://stackoverflow.com/questions/46267621/unable-to-merge-dex - Unable to merge dex – user784625 Oct 31 '17 at 11:55

6 Answers6

4

I looked up:

Error:Execution failed for task ':memDicez:transformDexArchiveWithExternalLibsDexMergerForDebug'.

com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

yesterday and found nothing usefull,

my issue is now solved,

this method might get you towards a solution (it worked for me, no guarantee it works for you)

I had:

android {
    compileSdkVersion 25
    buildToolsVersion '26.0.2'

    defaultConfig {
        applicationId "(my secret applicationId)"
        minSdkVersion 21
        targetSdkVersion 25
        multiDexEnabled true
    }

    ...

}

and

dependencies {
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support:support-v4:25.3.1'
    compile 'ch.acra:acra:4.9.2'
    //compile 'com.google.android.gms:play-services-auth:9.0.0'
    compile 'com.loopj.android:android-async-http:1.4.9'
    compile 'com.koushikdutta.ion:ion:2.+'
    compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'
}

and when I changed:

        minSdkVersion 21

to

        minSdkVersion 16

I got a more descriptive error message which did give solutions via google/stack overflow.

in my case

compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'

should be changed to

compile('com.googlecode.json-simple:json-simple:1.1.1') {
    exclude group: 'org.hamcrest', module: 'hamcrest-core'
}

You can change the minSdkVersion back to a higher value later on but decreasing it seems to give a more descriptive (or more googleable) problem (and solution)

cheers,

S.

SanThee
  • 2,301
  • 3
  • 23
  • 35
1

In your file build.gradle (Project: XXX), there is this snippet

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

Previously, that is 2.3.3, then became 3.0.0 when you updated your Android Studio. Try reverting it to 2.3.3 then Resync, then wait for your Android Studio to ask to update your Gradle and gradle plugin to 3.0.0. By this time, no build issues should appear related to Merge Dex.

Adrian Borja
  • 144
  • 2
  • 13
0

multiDexEnabled true

Example

android {
    compileSdkVersion 25
    buildToolsVersion '26.0.2'
    defaultConfig {
        applicationId "com.xx.xxx"
        minSdkVersion 15
        targetSdkVersion 24
        versionCode 9
        versionName "1.0"
        multiDexEnabled true //Add this
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            shrinkResources true
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    } }
Youness
  • 3
  • 1
0

Take a look in "Settings"->"Android SDK"->"SDK Tools" Google Play services is checked and installed v.46, while you there check if you need to update anything else for the new android version.

Clean and Rebuild the project. It should fix the problem, if not you can try to removed the .gradle folder and clean and rebuild again.

For me I also had to close all android projects and open android studio again and it worked smoothly.

Good luck,

SHAI86
  • 77
  • 1
  • 7
0

My issue was fixed by changing the minimal SDK to 16 and target SDK to 25, and adding multidexenabled=true in default.config. Add the follwing to in app/build.gradle:

compile 'com.android.support:appcompat-v7:25.+'
compile 'com.android.support:design:25.+'
clemens
  • 16,716
  • 11
  • 50
  • 65
Varun Chandran
  • 647
  • 9
  • 23
0

It started happening in my case after adding the following dependency.

implementation 'com.getbase:floatingactionbutton:1.9.0'

I've tried all suggestions published here and in other places, but nothing has worked.

I've tried then a common solution that helped in many other cases and it worked. I've simply used "Sync project with gradle files" from the following menu that can be found in Tools. enter image description here

Oleg Gryb
  • 5,122
  • 1
  • 28
  • 40