dexafree
dexafree

Reputation: 131

Multiple dex files error when downloading my library from Sonatype

I have developed a library that has been around for some months, and I'm having a problem when downloading it from Sonatype repositories (uploading it works fine).

My library is MaterialList, and it can be imported by

  1. Adding this line to your build.gradle file

    compile 'com.github.dexafree.materiallist:2.1.0'
    
  2. Cloning the project and adding the library as a module by hand

For testing, you can just clone the repo and try both options, changing the app/build.gradle line, from compile project() to the one in the first option

When you compile and run by setting the compile project option, it works perfectly.

But when it's downloaded from Sonatype, it complains about multiple dex files defining a class on a library I need inside my library.

The full trace is the following:

Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
    /[sdk-path]/android/sdk/build-tools/21.1.2/dx --dex --no-optimize --output /[project-path]/MaterialList/app/build/intermediates/dex/debug --input-list=/[project-path]/MaterialList/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/nhaarman/listviewanimations/util/Swappable;
      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)

Any suggestion about how to make it not happen?

Thanks in advance

Upvotes: 1

Views: 97

Answers (1)

nhaarman
nhaarman

Reputation: 100438

lib-manipulation and lib-core-slh both depend on lib-core themselves. As I see no reference to any StickyListHeaders stuff in your library, I don't think you need the lib-core-slh dependency. You should also be able to remove the lib-core dependency, since lib-manipulation includes this for you.

You could also try to include the dependencies directly, without the @aar suffix. Perhaps this messes things up.

compile 'com.nhaarman.listviewanimations:lib-core:3.1.0'
compile 'com.nhaarman.listviewanimations:lib-manipulation:3.1.0'
compile 'com.nhaarman.listviewanimations:lib-core-slh:3.1.0'

This could be an error on my part though. Let me know if any of these solutions work for you.

Upvotes: 1

Related Questions