2

I've a Android project which has some dependencies, One is 'org.parceler:parceler:0.2.16' and another one is 'com.google.guava:guava:18.0'. Both of them have 'com.google.thirdparty.publicsuffix' package as shown in the below image. Gradle configs synchronized with project successfully but when I want to compile project, I encounter with this error:

Error:Gradle: Execution failed for task ':app:dexDebug'.

com.android.ide.common.internal.LoggedErrorException: Failed to run command: C:\Users\Siamak\AppData\Local\Android\sdk\build-tools\21.1.2\dx.bat --dex --no-optimize --output C:\Users\Siamak\AndroidStudioProjects\HelloWorld\app\build\intermediates\dex\debug --input-list=C:\Users\Siamak\AndroidStudioProjects\HelloWorld\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/google/thirdparty/publicsuffix/PublicSuffixPatterns; 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)

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:20.0.0'
compile 'com.squareup.retrofit:retrofit:1.6.1'
compile 'com.jakewharton:butterknife:6.1.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile ('org.parceler:parceler:0.2.16')
compile 'org.apache.httpcomponents:httpmime:4.3.5'
compile ('com.google.guava:guava:18.0')

}

Sorry for images ;-) Image

Edit:

Mentioned question in the comments is not same situations, one solution is using exclude command on dependencies section, as I haven't any transitive dependency between project dependencies, It isn't useful. another solution is using special jar file (with a core or dep suffix like 'junit-dep' or 'mockito-core'), but I couldn't find any specific latest parceler jar file that does not include 'com.google.thirdparty.publicsuffix'. Please visit provided image link to understand problem better. Thanks.

Edit 2:

Project dependencies tree:

+--- com.android.support:appcompat-v7:20.0.0
|    \--- com.android.support:support-v4:20.0.0
|         \--- com.android.support:support-annotations:20.0.0
+--- com.squareup.retrofit:retrofit:1.6.1
|    \--- com.google.code.gson:gson:2.2.4
+--- com.jakewharton:butterknife:6.1.0
+--- com.squareup.picasso:picasso:2.5.2
+--- org.parceler:parceler:0.2.+ -> 0.2.16
|    \--- org.parceler:parceler-api:0.2.16
+--- org.apache.httpcomponents:httpmime:4.3.5
|    \--- org.apache.httpcomponents:httpclient:4.3.5
|         +--- org.apache.httpcomponents:httpcore:4.3.2
|         +--- commons-logging:commons-logging:1.1.3
|         \--- commons-codec:commons-codec:1.6
\--- com.google.guava:guava:18.0
Siamak S
  • 163
  • 9

2 Answers2

0

It sounds like the main problem is that org.parceler statically includes some guava classes, rather than just depending on the guava library.

I don't know how you can fix this in your gradle build, but a slightly different approach might be to contact the author of the library and/or submit a pull request directly to fix the problem. The project appears to be hosted on github

JesusFreke
  • 19,784
  • 5
  • 65
  • 68
0

If the problem is with Parceler's usage of Guava...

Parceler uses Guava only in the annotation processor, and it is shaded to avoid conflicts with other libraries or Guava being included directly. Therefore you can avoid including Parceler's Guava in the final dex pass by using Parceler via the apt or provided scope:

apply plugin: 'android-apt'

dependencies {
    apt 'org.parceler:parceler:1.0.1'
    compile 'org.parceler:parceler-api:1.0.1'
}

Although I'm not sure how this conflict is happening as part of the shading is a renaming of the root package for Guava from com.google.common to org.parceler.guava.

John Ericksen
  • 10,995
  • 4
  • 45
  • 75