Android Stduio dependency, multiple dex error, dex merger

1.3k Views Asked by At

Today I ran into an issue with multiple dex files when I added a library (MaterialDesignLibrary) to my project which was using another library(Float Labeled EditText).

Through research I found out that the conflict is from that the two libraries are both using nineoldandroids as a dependency. I tested and saw that Float Labeled EditText leads my project to add "library-2.4.0.jar" in my external libraries upon gradle syncing, while Material Design Library includes "nineoldandroids-2.4.0.jar" file under "/libs".

I tried deleting duplicates here and there, searched for solutions for hours, but still no luck.

In this case, is the jar file name the cause of multiple dex error due to dex merger failing? Or is DexMerger smart enough to figure out two different jar files are, in fact, the same dependency?

I have to say that I still do not clearly understand how DexMerger works.


Below is the error I get:

Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:

...

Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lcom/nineoldandroids/animation/Animator$AnimatorListener;
    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)

EDIT 12/5

I even tried putting only one copy of nineoldandroids-2.4.0.jar in app/libs, removed all the references including either jar or maven repo dependencies from other two modules (materialLib and floatlabeledittext). Then I added in the two modules

compile files(':app/libs/nineoldandroids-2.4.0.jar')

to make sure there is only one copy of the jar file being referenced.

build.gradle in my app has

compile project(':materialLib')
compile project(':floatlabeledittext')

under dependencies. Still multiple dex error. Also tried Clean, Gradle Sync, invalidate Caches/Restart. Any idea what I am missing?

1

There are 1 best solutions below

0
On

I too had a similar problem. Two of my library projects were using the nineoldandroids as dependency. So I excluded the nineoldandroids by adding the following code in the build.gradle file which resolved the issue :

compile ('com.balysv.materialmenu:material-menu:1.5.4') {
    exclude group: 'com.nineoldandroids', module: 'library'
}

Also see this link, for the same problem.