3

I am a new Android Developer and build files always scare me. :D I am using some third part libraries in the project

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:21.0.+'
    compile 'com.android.support:support-v4:21.0.3'
    compile 'com.android.support:cardview-v7:21.0.+'
    compile 'com.android.support:recyclerview-v7:21.0.+'
    compile 'de.hdodenhof:circleimageview:1.2.1'
    compile 'com.github.flavienlaurent.datetimepicker:library:0.0.2'
}

In addition to this I am also using MPAndroidChart(the only jar in the lib folder) which is only available as a jar file and not a gradle dependency.

MPAndroidChart uses NineOldAndroids as a dependency and I suspect one of my other libraries also uses it and it is causing a build fail.

Any idea how to make both these libraries behave?

I checked the similar questions and found one that was exactly my problem- Gradle error - Execution failed for task ':app:dexDebug'

But he was including the NineOldAndroids library on his own. So he just removed that line and it was working.

One idea that I had was to strip apart the jar and include them as java files in my project, but that seemed like overkill for this problem. I'm sure there must be an easier way?

This is my entire error

UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lcom/nineoldandroids/animation/ValueAnimator$AnimatorUpdateListener;
    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:454)
    at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
    at com.android.dx.command.dexer.Main.run(Main.java:246)
    at com.android.dx.command.dexer.Main.main(Main.java:215)
    at com.android.dx.command.Main.main(Main.java:106)


 FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:dexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
    C:\Users\manu.joseph\AppData\Local\Android\sdk\build-tools\21.1.2\dx.bat --dex --no-optimize --output C:\Users\manu.joseph\AndroidStudioProjects\WriteTrack\app\build\intermediates\dex\debug --input-list=C:\Users\manu.joseph\AndroidStudioProjects\WriteTrack\app\build\intermediates\tmp\dex\debug\inputList.txt
Error Code:
    2
Output:

    UNEXPECTED TOP-LEVEL EXCEPTION:
    com.android.dex.DexException: Multiple dex files define Lcom/nineoldandroids/animation/ValueAnimator$AnimatorUpdateListener;
        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:454)
        at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
        at com.android.dx.command.dexer.Main.run(Main.java:246)
        at com.android.dx.command.dexer.Main.main(Main.java:215)
        at com.android.dx.command.Main.main(Main.java:106)
Community
  • 1
  • 1
Manu Joseph
  • 155
  • 1
  • 13

4 Answers4

1

Add this to your build.gradle :

 configurations {
    all*.exclude group: 'com.nineoldandroids'
}

Works fine for me ;)

Jujumoz
  • 46
  • 6
  • This might work. I have no way of verifying it of course. I dumped MPAndroidChart and implemented HelloCharts. But thanks for the answer. – Manu Joseph Feb 22 '15 at 15:40
0

Remove the following line and try again

compile 'com.android.support:support-v4:21.0.3'
Gunaseelan
  • 14,415
  • 11
  • 80
  • 128
0

I'm a new android developer and not long before I post this answer, I'm facing the same problem too. Googling and only 2 stackoverflow question showed up. Your question, and the stackoverflow question you provided there.

Somehow, after I remove the unused dependency library via project structures (ctrl+alt+shift+s), in my case, it is

compile 'com.rengwuxian.materialedittext:library:1.8.2'

sync the gradle and then poof! I hope it works for you too.

muhrifqii
  • 19
  • 2
  • 9
0

In the end, I ended up adding the library as an external project which did the trick for me.

Detailed instructions here.. How do I add a library project to Android Studio?

Hope this helps someone..

Community
  • 1
  • 1
Manu Joseph
  • 155
  • 1
  • 13