Dex Exception when using google-http-client-jackson2

258 views
Skip to first unread message

Jeremy Roberson

unread,
Jul 1, 2014, 11:05:19 PM7/1/14
to robo...@googlegroups.com
I'll start off by saying that I'm new to Gradles and RobiSpice.  I'm using Android Studio(IntelliJ)

In my build.gradle file I have the following defined.

    compile 'com.octo.android.robospice:robospice:1.4.12'
    compile 'com.octo.android.robospice:robospice-google-http-client:1.4.12'

    compile('com.google.http-client:google-http-client-jackson2:1.18.0-rc')
            {
                exclude module: 'xpp3'
                exclude group: 'stax'
            }

My /libs directory contains the following libraries.

google-http-client-jackson2-1.18.0.rc.jar
robospice-1.4.12.jar
robospice-google-http-client-1.4.12.jar

The error I get when building is below.

* What went wrong:
Execution failed for task ':app:dexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
  /Applications/Android Studio.app/sdk/build-tools/android-4.4W/dx --dex --num-threads=4 --output /Users/jeremy.roberson/AndroidStudioProjects/SecondAmendmentSupporters/app/build/intermediates/dex/debug /Users/jeremy.roberson/AndroidStudioProjects/SecondAmendmentSupporters/app/build/intermediates/classes/debug /Users/jeremy.roberson/AndroidStudioProjects/SecondAmendmentSupporters/app/build/intermediates/dependency-cache/debug /Users/jeremy.roberson/AndroidStudioProjects/SecondAmendmentSupporters/app/build/intermediates/pre-dexed/debug/classes-69404226c1db6a41d5b932e2272da4fd5e0ab386.jar /Users/jeremy.roberson/AndroidStudioProjects/SecondAmendmentSupporters/app/build/intermediates/pre-dexed/debug/commons-io-1.3.2-b20e38d544e61daa90e71baf8893ad8a4231dd48.jar /Users/jeremy.roberson/AndroidStudioProjects/SecondAmendmentSupporters/app/build/intermediates/pre-dexed/debug/commons-lang3-3.3.2-b7e2995080bfbbafdb40d096817ba9213e87a032.jar /Users/jeremy.roberson/AndroidStudioProjects/SecondAmendmentSupporters/app/build/intermediates/pre-dexed/debug/google-http-client-1.18.0-rc-f63625e0872e226f00f7984d657b33afc588c466.jar /Users/jeremy.roberson/AndroidStudioProjects/SecondAmendmentSupporters/app/build/intermediates/pre-dexed/debug/google-http-client-android-1.18.0-rc-6a7f23a038cd45162289efc7f20aac9be83f7db2.jar /Users/jeremy.roberson/AndroidStudioProjects/SecondAmendmentSupporters/app/build/intermediates/pre-dexed/debug/google-http-client-jackson2-1.18.0-rc-039ae6ae2c993db20d3bc40af227f953e9fd3070.jar /Users/jeremy.roberson/AndroidStudioProjects/SecondAmendmentSupporters/app/build/intermediates/pre-dexed/debug/google-http-client-jackson2-1.18.0-rc-08fc8c6366bb09708d81cb105db37ee31ba67e25.jar /Users/jeremy.roberson/AndroidStudioProjects/SecondAmendmentSupporters/app/build/intermediates/pre-dexed/debug/jackson-core-2.1.3-873c6ed7376d68e1e6082ecb219c9b6fbeae12ef.jar /Users/jeremy.roberson/AndroidStudioProjects/SecondAmendmentSupporters/app/build/intermediates/pre-dexed/debug/jsr305-1.3.9-1dd65de12d7618a0fe4937b73ba02521513c41e9.jar /Users/jeremy.roberson/AndroidStudioProjects/SecondAmendmentSupporters/app/build/intermediates/pre-dexed/debug/robospice-1.4.12-696621df6072460deb0f4ca05c4b5b9ae5dcee65.jar /Users/jeremy.roberson/AndroidStudioProjects/SecondAmendmentSupporters/app/build/intermediates/pre-dexed/debug/robospice-cache-1.4.12-277f66148ae7c0718f6030b03f324a3ebe125dff.jar /Users/jeremy.roberson/AndroidStudioProjects/SecondAmendmentSupporters/app/build/intermediates/pre-dexed/debug/robospice-google-http-client-1.4.12-2ad96ad2beb363ad2562fd109be966ae38109e96.jar /Users/jeremy.roberson/AndroidStudioProjects/SecondAmendmentSupporters/app/build/intermediates/pre-dexed/debug/support-v4-19.0.1-3bf117e59e2e0f41bbf9219f2be90cdcf1dd583d.jar
  Error Code:
  2
  Output:
 
  UNEXPECTED TOP-LEVEL EXCEPTION:
  com.android.dex.DexException: Multiple dex files define Lcom/google/api/client/json/jackson2/JacksonFactory$1;
  at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:594)
  at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:552)
  at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:533)
  at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:170)
  at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
  at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439)
  at com.android.dx.command.dexer.Main.runMonoDex(Main.java:287)
  at com.android.dx.command.dexer.Main.run(Main.java:230)
  at com.android.dx.command.dexer.Main.main(Main.java:199)

Stéphane NICOLAS

unread,
Jul 2, 2014, 2:51:19 AM7/2/14
to robo...@googlegroups.com
Remove all files from libs folder. Gradle will manage your dependencies.

S.


--
Vous recevez ce message, car vous êtes abonné au groupe Google Groupes "RoboSpice".
Pour vous désabonner de ce groupe et ne plus recevoir d'e-mails le concernant, envoyez un e-mail à l'adresse robospice+...@googlegroups.com.
Pour obtenir davantage d'options, consultez la page https://groups.google.com/d/optout.

Jeremy Roberson

unread,
Jul 2, 2014, 3:42:06 PM7/2/14
to robo...@googlegroups.com
I tried removing all the libraries but then when I run, I get class not found exceptions.  

I got it to work but only by adding the following libraries and compile statements.  I needed to add the jackson1 library as well because some class in the robospice-google-http-client packages uses it.

    compile 'com.octo.android.robospice:robospice:1.4.12'
    compile 'com.octo.android.robospice:robospice-google-http-client:1.4.12'

    compile('com.google.http-client:google-http-client-jackson2:1.18.0-rc')
            {
                exclude module: 'xpp3'
                exclude group: 'stax'
            }
    compile('com.google.http-client:google-http-client-jackson:1.18.0-rc')
            {
                exclude module: 'xpp3'
                exclude group: 'stax'
            }

And under /lib

google-http-client-jackson-1.18.0-rc 12.29.21 PM.jar
google-http-client-jackson2-1.18.0-rc 12.29.21 PM.jar
robospice-1.4.12 12.29.21 PM.jar
robospice-google-http-client-1.4.12 12.29.21 PM.jar

Stéphane NICOLAS

unread,
Jul 2, 2014, 3:45:49 PM7/2/14
to robo...@googlegroups.com
Hi Jeremy,

let me be clear, you should NOT use any jar in libs folder. The only exception is when an artifact doesn't exist on a central repo, and even then there is better to do than putting raw jars in libs.

Try to get rid of all of them, and just get your app compile using the compile statements of gradle.

S.

Jeremy Roberson

unread,
Jul 2, 2014, 4:08:47 PM7/2/14
to robo...@googlegroups.com
Can you confirm that my compile statements are correct?

Do I have to configure repository access somewhere?

Jeremy Roberson

unread,
Jul 2, 2014, 4:37:12 PM7/2/14
to robo...@googlegroups.com
I'm not sure why but I removed the libs again did a thorough clean and rebuild and it works.  

Can you explain how the compile statements are resolved to repo locations or recommend a link?

Stéphane NICOLAS

unread,
Jul 2, 2014, 6:27:22 PM7/2/14
to robo...@googlegroups.com
Hi Jeremy,

please follow our gradle setup page on the wiki. Also try this command : gradle depdencies and have a look at the depencies imported by gradle to avoir importing it twice. But that should be fine or close to it. 
And with gradle, the only thing to do to get access to the maven central repo is to use the statement mavenCentral(), that's it.

I am sorry as I may look fuzzy, be really, on this matter our library is not different than any other on android or in Java at large.

Stéphane

Reply all
Reply to author
Forward
0 new messages