com.android.dex.DexException: Multiple dex files define Ljavax/annotation/CheckForNull;

JIRA | Tomás GP | 9 months ago
  1. 0

    Impacted Cases ============== In an Android project that uses Gradle, it becomes a nuisance mixing Xwalk with other libraries that uses the JSR305 dependency. The compilation fails and the developer must learn about how to workaround the dependency problem. In my case, I detected this case because I used Facebook's Stetho that depends on JSR305: ./gradlew :app:dependencies +--- com.facebook.stetho:stetho:1.3.1 | +--- com.google.code.findbugs:jsr305:2.0.1 | \--- commons-cli:commons-cli:1.2 Reproduce Test Steps ==================== 1. Add the Xwalk dependency to your build.gradle file following the official instructions. 2. Add a library that uses the JSR305 artifact to your build.gradle, like Facebook's Stetho. Add this line into the dependencies block: compile 'com.facebook.stetho:stetho:1.3.1' 3. Try to compile your project: ./gradlew clean assembleX86Debug Expected Outcome ================ BUILD SUCCESSFUL Actual Outcome ============== BUILD FAILED , because of this exception: UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexException: Multiple dex files define Ljavax/annotation/CheckForNull; 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) Test Case Source Code ===================== There's a project attached to check the issue. Check the app/build.gradle file. In the dependencies block, it contains what the user is going to do and in a comment, the current workaround to make possible the compilation. Please, notice that this could happen with another jar that embeds the JS305 dependency like XWalk currently, making impossible to use this workaround. The workaround involves excluding the JSR305 dependency like this: compile ('com.facebook.stetho:stetho:1.3.1') { exclude module: 'jsr305'; }

    JIRA | 9 months ago | Tomás GP
    com.android.dex.DexException: Multiple dex files define Ljavax/annotation/CheckForNull;
  2. 0

    GitHub comment 62#206876390

    GitHub | 8 months ago | benas
    com.android.dex.DexException: Multiple dex files define Ljavax/annotation/CheckForNull;
  3. 0

    Impacted Cases ============== In an Android project that uses Gradle, it becomes a nuisance mixing Xwalk with other libraries that uses the JSR305 dependency. The compilation fails and the developer must learn about how to workaround the dependency problem. In my case, I detected this case because I used Facebook's Stetho that depends on JSR305: ./gradlew :app:dependencies +--- com.facebook.stetho:stetho:1.3.1 | +--- com.google.code.findbugs:jsr305:2.0.1 | \--- commons-cli:commons-cli:1.2 Reproduce Test Steps ==================== 1. Add the Xwalk dependency to your build.gradle file following the official instructions. 2. Add a library that uses the JSR305 artifact to your build.gradle, like Facebook's Stetho. Add this line into the dependencies block: compile 'com.facebook.stetho:stetho:1.3.1' 3. Try to compile your project: ./gradlew clean assembleX86Debug Expected Outcome ================ BUILD SUCCESSFUL Actual Outcome ============== BUILD FAILED , because of this exception: UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexException: Multiple dex files define Ljavax/annotation/CheckForNull; 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) Test Case Source Code ===================== There's a project attached to check the issue. Check the app/build.gradle file. In the dependencies block, it contains what the user is going to do and in a comment, the current workaround to make possible the compilation. Please, notice that this could happen with another jar that embeds the JS305 dependency like XWalk currently, making impossible to use this workaround. The workaround involves excluding the JSR305 dependency like this: compile ('com.facebook.stetho:stetho:1.3.1') { exclude module: 'jsr305'; }

    JIRA | 9 months ago | Tomás GP
    com.android.dex.DexException: Multiple dex files define Ljavax/annotation/CheckForNull;
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Your lib can't coexist with other dependencies including support-v4

    GitHub | 2 years ago | theGlenn
    com.android.dex.DexException: Multiple dex files define Landroid/support/v4/app/BackStackState;
  6. 0

    Android Studio, Google Drive and Sheets API not playing along

    Stack Overflow | 2 years ago | Liquid Ink
    com.android.dex.DexException: Multiple dex files define Ljavax/annotation/CheckForNull;

    46 unregistered visitors
    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. com.android.dex.DexException

      Multiple dex files define Ljavax/annotation/CheckForNull;

      at com.android.dx.merge.DexMerger.readSortableTypes()
    2. Android SDK's dx Tool
      Main.main
      1. com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:579)
      2. com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:535)
      3. com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:517)
      4. com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:164)
      5. com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
      6. com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:504)
      7. com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
      8. com.android.dx.command.dexer.Main.run(Main.java:277)
      9. com.android.dx.command.dexer.Main.main(Main.java:245)
      10. com.android.dx.command.Main.main(Main.java:106)
      10 frames