Android Gradle Exception: "Define multiple dex files", duplicated classes under explosion-aar

I am trying to use my aar library (the maven project created using the android-maven-plugin from Jayway) in the gradle project, but when I run gradle assembleDebug , I have the following exception:

 UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/actions/ItemListIntents; at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596) at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554) at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535) at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171) at com.android.dx.merge.DexMerger.merge(DexMerger.java:189) at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:502) 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) 

If I look for this class in my project, Android Studio will find two results:

  • ListItemIntents (com.google.android.gms.action) play-services-base-7.0.0(classes.jar)
  • ListItemIntents (com.google.android.gms.action) aar-library(classes.jar)

Running gradle dependencyInsight --dependency play-services-base --configuration compile I get:

 com.google.android.gms:play-services-base:7.0.0 +--- com.google.android.gms:play-services-gcm:7.0.0 | \--- aar-library:core:1.0.10-SNAPSHOT | \--- compile +--- com.google.android.gms:play-services-location:7.0.0 | \--- com.nexse.mobile.betting.core:core:1.0.10-SNAPSHOT (*) \--- com.google.android.gms:play-services-maps:7.0.0 \--- com.google.android.gms:play-services-location:7.0.0 (*) (*) - dependencies omitted (listed previously) 

The problem in the classes.jar library: ListIntentIntents (and, obviously, the entire module of game services) already exists! So inside

 my-gradle-project/app/build/intermediates/exploded-aar/ 

I have two links to the play-services-base module: one in the com.google.android.gms folder, one in the aar-library folder

What should I do?

+5
source share
3 answers

I found a criminal! I used the old Android module maven com.jayway.maven.plugins.android.generation2

The new com.simpligility.maven.plugins fixed the error.

Anyway, thanks for the help.

+1
source

You can try to enable multidex enable true in the gradle file as follows:

 android { compileSdkVersion 22 buildToolsVersion "23.0.0" defaultConfig { minSdkVersion 14 //lower than 14 doesn't support multidex targetSdkVersion 22 // Enabling multidex support. multiDexEnabled true } } 
0
source

If the number of method references in the application exceeds the limit of 65K, your application may not compile. You can fix this problem when compiling your application by specifying only the specific Google Play that are used by your application, and not all of them.

The above expressions are taken from https://developers.google.com/android/guides/setup .

First: Click Clean Project from the Build Item in the menu bar (Android Studio).

Second: Try adding separate dependencies. Example. If you want to use location services only, add compile 'com.google.android.gms:play-services-location:7.8.0' only in build.gradle .

0
source

Source: https://habr.com/ru/post/1232001/


All Articles