Search code examples
javajarskmaps

How to solve conflict dependence with SKMaps.jar and guava


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


Solution

  • There are 2 options, the first being easier than the second one:

    1. Deleting the Google package from the already compiled 'SKMaps.jar' file

      • make a backup of the SKMaps.jar file
      • open the .jar file with an archive reader, for ex. 7zip
      • from the 3 folders, enter 'com' -> then select the google folder & delete it
      • close the archive saving it automatcally, there will be no error after this
      • *BUT you have to ensure the availibility of the Guava library along with the SKMaps.jar in the project (have it included in the lib folder)
    2. 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

      • the difference is that this option will not modify the original SKMaps.jar but make a copy of it without the duplicate package

    Applying either approach, the project will compile without any problems.