Search code examples
restandroid-annotationsspring-android

Multiple dex files define Lorg/springframework/http/ContentCodingType$1


I test androidannotations framework, but have some error when I add spring-android libs. I create repo for my test project open_git_repo !

At this moment, I have in gradle console


AGPBI: {"kind":"SIMPLE","text":"UNEXPECTED TOP-LEVEL EXCEPTION:","position":       {},"original":"UNEXPECTED TOP-LEVEL EXCEPTION:"}
AGPBI: {"kind":"SIMPLE","text":"com.android.dex.DexException: Multiple dex    files define Lorg/springframework/http/ContentCodingType$1;","position{},"original":"com.android.dex.DexException: Multiple dex files define Lorg/springframework/http/ContentCodingType$1;"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:594)","position":{},"original":"\tat com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:594)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:552)","position":{},"original":"\tat        com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:552)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:533)","position":{},"original":"\tat com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:533)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:170)","position":{},"original":"\tat com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:170)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.merge.DexMerger.merge(DexMerger.java:188)","position":{},"original":"\tat com.android.dx.merge.DexMerger.merge(DexMerger.java:188)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439)","position":{},"original":"\tat com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.command.dexer.Main.runMonoDex(Main.java:287)","position":{},"original":"\tat com.android.dx.command.dexer.Main.runMonoDex(Main.java:287)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.command.dexer.Main.run(Main.java:230)","position":{},"original":"\tat com.android.dx.command.dexer.Main.run(Main.java:230)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.command.dexer.Main.main(Main.java:199)","position":{},"original":"\tat com.android.dx.command.dexer.Main.main(Main.java:199)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.command.Main.main(Main.java:103)","position":{},"original":"\tat com.android.dx.command.Main.main(Main.java:103)"} 
AGPBI: {"kind":"SIMPLE","text":"UNEXPECTED TOP-LEVEL EXCEPTION:","position":{},"original":"UNEXPECTED TOP-LEVEL EXCEPTION:"}
AGPBI: {"kind":"SIMPLE","text":"com.android.dex.DexException: Multiple dex files define Lorg/springframework/http/ContentCodingType$1;","position":{},"original":"com.android.dex.DexException: Multiple dex files define Lorg/springframework/http/ContentCodingType$1;"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:594)","position":{},"original":"\tat com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:594)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:552)","position":{},"original":"\tat com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:552)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:533)","position":{},"original":"\tat com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:533)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:170)","position":{},"original":"\tat com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:170)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.merge.DexMerger.merge(DexMerger.java:188)","position":{},"original":"\tat com.android.dx.merge.DexMerger.merge(DexMerger.java:188)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439)","position":{},"original":"\tat com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.command.dexer.Main.runMonoDex(Main.java:287)","position":{},"original":"\tat com.android.dx.command.dexer.Main.runMonoDex(Main.java:287)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.command.dexer.Main.run(Main.java:230)","position":{},"original":"\tat com.android.dx.command.dexer.Main.run(Main.java:230)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.command.dexer.Main.main(Main.java:199)","position":{},"original":"\tat com.android.dx.command.dexer.Main.main(Main.java:199)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.command.Main.main(Main.java:103)","position":{},"original":"\tat com.android.dx.command.Main.main(Main.java:103)"}


 FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:dexDebug'.
> com.android.ide.common.process.ProcessException:org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.6.0_45\bin\java.exe'' finished with non-zero exit value 2

* Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

My build gradle script


buildscript {
repositories {
    maven {
        url 'http://repo.spring.io/milestone'
    }
    jcenter()
}
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'}
}
apply plugin: 'com.android.application'

android {
   compileSdkVersion 19
buildToolsVersion "20.0.0"
defaultConfig {
    applicationId "com.example.mbykov.myapplication"
    minSdkVersion 15
    targetSdkVersion 15
    versionCode 1
    versionName "1.0"
}
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
def AAVersion = '3.3'
dependencies {
    apt "org.androidannotations:androidannotations:3.3"
    compile "org.androidannotations:androidannotations-api:3.3"
}
apt {
    arguments {
        androidManifestFile variant.outputs[0].processResources.manifestFile
    }
}
sourceSets {}
packagingOptions {
    exclude 'META-INF/DEPENDENCIES.txt'
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/dependencies.txt'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/license.txt'
    exclude 'META-INF/LGPL2.1'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/notice.txt'
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
//compile 'org.springframework.android:spring-android-rest-template:2.0.0.BUILD-SNAPSHOT'
 compile 'org.springframework.android:spring-android-rest-   template:1.0.1.RELEASE'
}
repositories {
maven {
    url 'http://repo.spring.io/snapshot'
}}

I don't understand this error, could somebody explain what is going on?


Solution

  • Two things:

    First, the declared dependencies:

    //compile 'org.springframework.android:spring-android-rest-template:2.0.0.BUILD-SNAPSHOT'
     compile 'org.springframework.android:spring-android-rest-   template:1.0.1.RELEASE
    

    I know you commented out the first dependency, but make sure you do not have two at the some time. This will cause duplicate classes in your classpath and dex fails.

    Secondly, you have the spring android rest template jar in your libs folder. This will also cause duplicate, since you are referring to this library as a dependency from repository, and also as a dependency from your local libs folder. Just delete the libs folder, it is totally unnecessary. You should always use proper dependency management, e.g. just declare them in your buildscript and let gradle download them with transitive dependencies, correct version and dependency conflict resolution etc. Remove this line, too:

    compile fileTree(include: ['*.jar'], dir: 'libs')