0

My code is build but when i try to run the code following exception occurs:

com.android.ide.common.internal.LoggedErrorException: Failed to run command:
C:\adt-bundle-windows-x86_64-20140624\sdk\build-tools\20.0.0\dx.bat --dex --no-optimize --output 

Error Code: 2

Output:

UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lcom/google/gson/JsonSerializer;
    at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:594)
    at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:552)

I read a few of the similar problems but most of them were working after adding exclude clause or adding transitive statement. I'm using gradle 2.2 and The problem still exists . My dependency block as follows:

dependencies {
compile project(':volley')
compile project(':jumioSDK')
compile project(':parallaxScroll')
compile 'com.android.support:appcompat-v7:19.1.0'
compile 'com.google.android.gms:play-services:6.1.71'
compile ('org.springframework.android:spring-android-rest-template:1.0.1.RELEASE')
compile ('org.codehaus.jackson:jackson-mapper-asl:1.9.13')
compile ('org.codehaus.jackson:jackson-core-asl:1.9.13')
compile 'joda-time:joda-time:2.3'
compile (project(':AndroidIBeaconLibrary-1.0'))
compile (project(':SOLOMOExchangeSdk-1.0'))
compile 'com.google.code.gson:gson:2.3.1'
}

the dependency chart

+--- version1.7_solomo:volley:unspecified

+--- version1.7_solomo:jumioSDK:unspecifie

|    \--- LOCAL: jumio_netswipe_sdk_2.0.3.jar

+--- version1.7_solomo:parallaxScroll:unspecified

+--- com.android.support:appcompat-v7:19.1.0

|    \--- com.android.support:support-v4:20.0.0

|         \--- LOCAL: internal_impl-20.0.0.jar

+--- com.google.android.gms:play-services:6.1.71

|    \--- com.android.support:support-v4:20.0.0

|         \--- LOCAL: internal_impl-20.0.0.jar

+--- version1.7_solomo:AndroidIBeaconLibrary-1.0:unspecified

\--- version1.7_solomo:SOLOMOExchangeSdk-1.0:unspecified

     +--- LOCAL: estimote-sdk-preview.jar

     +--- LOCAL: gson-2.2.2.jar

     +--- LOCAL: jmockit-no-junit.jar

     +--- LOCAL: signalr-client-sdk-1.0.jar

     \--- LOCAL: signalr-client-sdk-android.jar
jjm
  • 6,028
  • 2
  • 24
  • 27
UDI
  • 1,602
  • 1
  • 14
  • 13
  • Quick google search turned up this answer: http://stackoverflow.com/questions/20989317/multiple-dex-files-define-landroid-support-v4-accessibilityservice-accessibility#answer-21100040, could you run the gradle commands it suggests and show the output? – jjm Jan 05 '15 at 21:32
  • So, your version1.7_solomo:SOLOMOExchangeSdk-1.0 library is including gson. Just use the `exclude` method described in that answer. – jjm Jan 05 '15 at 22:15
  • compile(project(':SOLOMOExchangeSdk-1.0')) { exclude group: 'com.google.code.gson' } changed the error to UNEXPECTED TOP-LEVEL EXCEPTION: java.lang.IllegalArgumentException: already added: Lcom/google/gson/annotations/Expose; at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:122) – UDI Jan 05 '15 at 22:59

1 Answers1

1
  • Update your libs/aars projects version with the latest version
  • Rather than using build.gradle to import your libs/aars instead put into /libs folder

Here I was having this problem and my solution was removing "gson-2.2.4.jar" from /libs and importing by gradle, using

compile 'com.google.code.gson:gson:2.2.4'

instead of

compile files('libs/gson-2.2.4.jar')

Works like a charm.

Ellie Kesselman
  • 899
  • 1
  • 17
  • 34
Rafa Araujo
  • 314
  • 1
  • 2
  • 9