Reputation: 3746
I have two packages as dependencies in an Android project: A and B, defined in build.gradle
as following:
dependencies {
compile 'dependency-A'
compile files('libs/dependency-B.jar')
}
I can build the project, however when trying to run it I get the following error:
:app:compileDebugSources
:app:transformClassesWithDexForDebug
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lcommon/package/in/both/Dependencies;
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)
FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformClassesWithDexForDebug'.
How can I exclude common package or do something about it, so that it would build and run correctly?
I'm using Android Studio 1.5.1, buildToolsVersion 23.0.2, com.android.tools.build:gradle:1.5.0
Upvotes: 1
Views: 550
Reputation: 3746
I haven't found easy and clean solution yet, however here is one possible workaround (if decompiling of any dependency is not prohibited):
Remove common package/classes from dependency-A
: unzip .jar file, remove the files, zip the remaining files back in the jar;
Decompile dependency-B
with any java-decompiler, e.g. with this one;
Add decompiled dependency-B
.java
files as part of your module sources or maybe as a separate one;
Build and run the project.
Upvotes: 0