多个dex文件定义Lorg / springframework / http / ContentCodingType $ 1

时间:2015-05-12 08:33:26

标签: rest android-annotations spring-android

我测试androidannotations框架,但是当我添加spring-android libs时会出现一些错误。 我为我的测试项目open_git_repo 创建了回购!

此时此刻,我已进入gradle控制台

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.

我的构建gradle脚本

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'
}}

我不明白这个错误,有人可以解释发生了什么吗?

1 个答案:

答案 0 :(得分:2)

两件事:

首先,声明的依赖项:

//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

我知道你注释掉了第一个依赖项,但请确保在某个时候没有两个依赖项。这将导致类路径中的重复类,并且dex失败。

其次,你的 libs 文件夹中有spring android rest模板jar。这也会导致重复,因为您将此库称为存储库中的依赖项,也是本地 libs 文件夹中的依赖项。只需删除 libs 文件夹,完全没必要。您应始终使用适当的依赖关系管理,例如只需在您的buildscript中声明它们,并让gradle下载它们,具有传递依赖,正确的版本和依赖冲突解决等。也删除这一行:

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