0
votes

Receiving this exception whilst trying to build my project. Have searched around for an answer but most cases seem to be different to mine.

Other solutions include clearing temporary files or doing a gradle clean. This does temporarily solve the issue but it reappears again after a few builds. Another way this issue can occur is if the project contains multiple copies of a library. I have searched through my project and only have one instance of activation.jar which is in my libs directory. Most other solutions seem to involve changing the build path in Eclipse, but my problem is occurring on Android Studio 0.5.8. I am using Java 1.7.

Gradle Console

UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexException: Multiple dex files define Lcom/sun/activation/registries/LineTokenizer; at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:594) at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:552) at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:533) at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:170) at com.android.dx.merge.DexMerger.merge(DexMerger.java:188) at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439) at com.android.dx.command.dexer.Main.runMonoDex(Main.java:287) at com.android.dx.command.dexer.Main.run(Main.java:230) at com.android.dx.command.dexer.Main.main(Main.java:199) at com.android.dx.command.Main.main(Main.java:103)

Libraries in libs dir:

  • activation.jar
  • additionnal.jar
  • androidplot-core-0.5.1.jar
  • annotations.jar
  • DatawindAdsSdk-2.0.jar
  • jpct_ae.jar
  • jsr305-1.3.9.jar
  • libGoogleAnalyticsV2.jar
  • mail.jar
  • twitter4j-core-3.0.5.jar

Dependencies: Note - ":android-cropimage" does not have any dependencies in build.gradle

Main module:

dependencies {
    //Library Projects
    compile project(':android-cropimage')
    compile project(':facebook')

    //Android SDK Libraries
    //This library requires "Google Play Services" and "Google Repository" to be downloaded via SDK Manager.
    compile 'com.google.android.gms:play-services:4.4.52'

    //Third Party
    compile fileTree(dir: 'libs', include: '*.jar')
    compile 'com.github.chrisbanes.actionbarpulltorefresh:extra-abs:+'
    compile 'com.jakewharton:butterknife:4.0.1'
    compile 'com.j256.ormlite:ormlite-core:4.46'
    compile 'com.j256.ormlite:ormlite-android:4.46'
    compile 'net.hockeyapp.android:HockeySDK:3.0.1'
    compile 'org.apache.httpcomponents:httpmime:4.2.5'
    compile 'com.viewpagerindicator:library:2.4.1@aar'
    compile 'com.squareup.picasso:picasso:2.2.0'
    compile 'com.mcxiaoke.volley:library:1.0.+'
    compile 'org.msgpack:msgpack:0.6.11'
}

Facebook module:

dependencies {
    compile 'com.android.support:support-v4:19.1.0'
}
2
"I have searched through my project and only have one instance of activation.jar which is in my libs directory" -- what other dependencies do you have? For example, are you referencing any JARs or AARs from Maven Central?CommonsWare
@CommonsWare I have added my dependencies and libs contents.Morepork

2 Answers

3
votes

Turns out this is due to a bug with the Android Gradle plugin's incremental dex option on version 0.10.2 (https://groups.google.com/forum/#!topic/adt-dev/6KbhReCE_fo). Removing the following from my build.gradle file solved the issue:

android {
    dexOptions {
        incremental true
    }
}
0
votes

As @Marepork anwered there is a bug withing gradle that has not been fixed

If you still want to use incremental build you can always use build variants and fordebug use multidex and for release a proguard