I'm working on a project which use OSM by Skobbler. my project needs to use a Google's library called guava. I have the SKMaps.jar placed on libs/SKMaps.jar, also another jars too. On the other side i got some dependencies like:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:19.1.+'
compile 'com.squareup.okhttp:okhttp:2.2.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.2.0'
compile group: 'com.google.guava', name: 'guava', version: '18.0'
}
This cause a conflict when you build the project, like this
Error:Execution failed for task ':app:dexPlatoDebug'.
com.android.ide.common.internal.LoggedErrorException: Failed to run command: /home/opt/android-studio/sdk/build-tools/21.1.0/dx --dex --no-optimize --output /home/alex/Android/proy/app/build/intermediates/dex/plato/debug --input-list=/home/alex/Android/proy/app/build/intermediates/tmp/dex/plato/debug/inputList.txt Error Code: 2 Output: UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexException: Multiple dex files define Lcom/google/common/annotations/Beta; 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:302) at com.android.dx.command.dexer.Main.run(Main.java:245) at com.android.dx.command.dexer.Main.main(Main.java:214) at com.android.dx.command.Main.main(Main.java:106)
As we can see here the conflict arise because SKMaps has a dependence from
Lcom/google/common/annotations/Beta;
And I say SKMaps because i have been doing some tests on a side project to detect which jars has conflicts, and SKMaps.jar and guava combinations has this conflict. Now here is my question:
How can i exclude the guava dependence from SKMaps.jar?
or
Is possible to aisle both jars to not cause conflict?
Thanks
There are 2 options, the first being easier than the second one:
Deleting the Google package from the already compiled 'SKMaps.jar' file
Write a gradle script which decompiles the SKMaps.jar and recompiles it with the com/google/ folder excluded (which is basically the same thing as the first option) and including the new jar in the build process
Applying either approach, the project will compile without any problems.