Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle - DexException: Multiple dex files define

I know this question has been asked already but I cannot find a suitable answer for my problem among the available solutions. I hope you guys can help me out.

The exception tells that Multiple dex files defined and I tried several common ways to fix this problem. Unfortunately, this didn't help.

* What went wrong:
Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2



Cause: com.android.dex.DexException: Multiple dex files define Lnet/jcip/annotations/GuardedBy;
        UNEXPECTED TOP-LEVEL EXCEPTION:
        com.android.dex.DexException: Multiple dex files define Lnet/jcip/annotations/GuardedBy;
            at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:579)
            at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:535)
            at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:517)
            at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:164)
            at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
            at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:504)
            at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
            at com.android.dx.command.dexer.Main.run(Main.java:277)
            at com.android.dx.command.dexer.Main.main(Main.java:245)
            at com.android.dx.command.Main.main(Main.java:106)
  1. I tried to clean and rebuild the project.

    • Build -> Clean Project
    • Build -> Rebuild Project
  2. Then I tried to Invalidate Caches and Restart.

    • File -> Invalidate Caches and Restart
  3. I also run this command to understand the duplications in dependencies:

    ./gradlew -q dependencies app:dependencies --configuration compile --stacktrace

and here is the output. As you can see there are no duplications.

+--- com.jakewharton.hugo:hugo-annotations:1.2.1
+--- com.google.code.findbugs:annotations:3.0.1
|    +--- net.jcip:jcip-annotations:1.0
|    \--- com.google.code.findbugs:jsr305:3.0.1
+--- com.michaelpardo:activeandroid:3.1.0-SNAPSHOT
+--- com.android.support:appcompat-v7:23.1.1
+--- com.crashlytics.sdk.android:crashlytics:2.3.0
|    +--- com.crashlytics.sdk.android:crashlytics-core:2.3.0
|    |    \--- io.fabric.sdk.android:fabric:1.3.1
|    +--- io.fabric.sdk.android:fabric:1.3.1
|    \--- com.crashlytics.sdk.android:beta:1.1.2
|         \--- io.fabric.sdk.android:fabric:1.2.0 -> 1.3.1
+--- com.greenhalolabs:emailautocompletetextview:1.3.0
+--- com.facebook.android:facebook-android-sdk:4.2.0
|    \--- com.parse.bolts:bolts-android:1.2.0
+--- com.android.support:cardview-v7:23.1.1
+--- com.jakewharton.hugo:hugo-runtime:1.2.0
|    +--- com.jakewharton.hugo:hugo-annotations:1.2.0 -> 1.2.1
|    \--- org.aspectj:aspectjrt:1.8.5
+--- joda-time:joda-time:2.0
+--- io.keen:keen-client-api-android:2.1.2
+--- com.googlecode.libphonenumber:libphonenumber:6.3.1
+--- net.simonvt.menudrawer:menudrawer:3.0.6
+--- com.squareup:otto:1.3.0
+--- com.google.android.gms:play-services-base:8.4.0
|    \--- com.google.android.gms:play-services-basement:8.4.0
+--- com.google.android.gms:play-services-analytics:8.4.0
+--- com.google.android.gms:play-services-gcm:8.4.0
|    \--- com.google.android.gms:play-services-measurement:8.4.0
+--- com.jeremyfeinstein.slidingmenu:library:1.3
+--- com.android.support:support-v4:23.1.1
|    \--- com.android.support:support-annotations:23.1.1
+--- com.jakewharton.timber:timber:3.1.0
+--- com.viewpagerindicator:library:2.4.1
+--- com.ouralabs:ouralabs:2.7.0
+--- com.android.support.test.espresso:espresso-idling-resource:2.2.1
+--- project :domain
|    \--- joda-time:joda-time:2.0
\--- project :remote
     +--- com.squareup.retrofit:retrofit:1.6.0
     |    \--- com.google.code.gson:gson:2.2.4
     +--- com.squareup.okhttp:okhttp:2.4.0
     |    \--- com.squareup.okio:okio:1.4.0
     \--- com.squareup.okhttp:okhttp-urlconnection:2.4.0
  1. I also read about the multiDexEnabled true but I'm sure that I didn't exceed the methods limit. This issue appeared instantly and without adding any libraries. I even can't assemble the older production versions of the code. They are in production and absolutely compilable.

Module's build.gradle:

dependencies {
    apply plugin: 'idea'

    compile "com.michaelpardo:activeandroid:${rootProject.ext.activeandroid}"
    compile(group: 'com.google.code.findbugs', name: 'annotations', version: "${rootProject.ext.findbugs}") {
        exclude(group: 'net.jcip', module: 'jcip-annotations')
    }
    compile(group: 'com.android.support', name: 'appcompat-v7', version: "${rootProject.ext.supportv4}") {
        exclude(group: 'com.android.support', module: 'support-v4')
    }
    compile(group: 'com.crashlytics.sdk.android', name: 'crashlytics', version: "${rootProject.ext.crashlytics}") {
        exclude(group: 'com.crashlytics.sdk.android', module: 'answers')
    }
    compile "com.greenhalolabs:emailautocompletetextview:${rootProject.ext.emailautocomplete}"
    compile(group: 'com.facebook.android', name: 'facebook-android-sdk', version: "${rootProject.ext.facebook}") {
        exclude(group: 'com.android.support', module: 'support-v4')
    }
    compile "com.android.support:cardview-v7:${rootProject.ext.supportv4}"
    compile "com.jakewharton.hugo:hugo-runtime:${rootProject.ext.hugo}"
    compile "joda-time:joda-time:${rootProject.ext.jodatime}"
    compile "io.keen:keen-client-api-android:${rootProject.ext.keen}"
    compile "com.googlecode.libphonenumber:libphonenumber:${rootProject.ext.libphonenumber}"
    compile "net.simonvt.menudrawer:menudrawer:${rootProject.ext.menudrawer}"
    compile "com.squareup:otto:${rootProject.ext.otto}"
    compile(group: 'com.google.android.gms', name: 'play-services-base', version: "${rootProject.ext.playservices}") {
        exclude(group: 'com.android.support', module: 'support-v4')
    }
    compile(group: 'com.google.android.gms', name: 'play-services-analytics', version: "${rootProject.ext.playservices}") {
        exclude(group: 'com.google.android.gms', module: 'play-services-basement')
    }
    compile(group: 'com.google.android.gms', name: 'play-services-gcm', version: "${rootProject.ext.playservices}") {
        exclude(group: 'com.google.android.gms', module: 'play-services-base')
        exclude(group: 'com.google.android.gms', module: 'play-services-basement')
    }
    compile "com.jeremyfeinstein.slidingmenu:library:${rootProject.ext.slidingmenu}"
    compile "com.android.support:support-v4:${rootProject.ext.supportv4}"
    compile "com.jakewharton.timber:timber:${rootProject.ext.timber}"
    compile "com.viewpagerindicator:library:${rootProject.ext.viewpagerindicator}"
    compile "com.ouralabs:ouralabs:${rootProject.ext.ouralabs}"
    compile "com.android.support.test.espresso:espresso-idling-resource:$rootProject.ext.espressoVersion"

    compile project(':domain')
    compile(project(':remote')) {
        exclude module: 'domain'
    }

    // Local Unit testing
    testCompile "junit:junit:$rootProject.ext.junit"
    testCompile "org.mockito:mockito-all:$rootProject.ext.mockitoVersion"
    testCompile "org.hamcrest:hamcrest-all:$rootProject.ext.hamcrestVersion"

    // Instrumentation Testing
    androidTestCompile "com.android.support.test.espresso:espresso-core:$rootProject.ext.espressoVersion"
    androidTestCompile "com.android.support.test.espresso:espresso-contrib:$rootProject.ext.espressoVersion"
    androidTestCompile "com.android.support.test.espresso:espresso-intents:$rootProject.ext.espressoVersion"
    androidTestCompile "com.android.support.test.uiautomator:uiautomator-v18:$rootProject.ext.uiautomator"
    androidTestCompile "com.android.support.test:runner:$rootProject.ext.runnerVersion"
    androidTestCompile "com.android.support.test:rules:$rootProject.ext.runnerVersion"
    androidTestCompile "org.mockito:mockito-core:$rootProject.ext.mockitoVersion"
    androidTestCompile "com.google.dexmaker:dexmaker:$rootProject.ext.dexmaker"
    androidTestCompile "com.google.dexmaker:dexmaker-mockito:$rootProject.ext.dexmaker"
}

UPDATE

I checked the project for GuardedBy. Is it looks like duplication?

enter image description here

like image 759
Val Avatar asked Jan 15 '16 15:01

Val


1 Answers

Looks like hugo-annotations is included twice. It's a dependency of hugo-runtime and added from somewhere else. Try excluding it from the hugo-runtime

compile("com.jakewharton.hugo:hugo-runtime:${rootProject.ext.hugo}") {
    exclude(group: 'com.jakewharton.hugo' module: 'hugo-annotations')
}

Also since the error is due to the jsr library may need to exclude it from the findbugs dependency.

compile(group: 'com.google.code.findbugs', name: 'annotations', version: "${rootProject.ext.findbugs}") {
    exclude(group: 'net.jcip', module: 'jcip-annotations')
    exclude(group: 'com.google.code.findbugs', module: 'jsr305')
}

Edit:

There is a nuclear option if you really can't find it, but I'm not sure if it would break something else or is best practice. This removes jsr305 from the classpath completely.

dependencies {
    ...
}
configurations.all*.exclude module: 'jsr305'
like image 106
JBirdVegas Avatar answered Nov 15 '22 01:11

JBirdVegas