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

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

我测试了 android 注释框架,但是当我添加 spring-android 库时出现了一些错误。 我为我的测试项目创建了 repo 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;","position{},"original":"com.android.dex.DexException: Multiple dex files define Lorg/springframework/http/ContentCodingType;"}
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;","position":{},"original":"com.android.dex.DexException: Multiple dex files define Lorg/springframework/http/ContentCodingType;"}
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'
}}

我不明白这个错误,有人能解释一下这是怎么回事吗?

两件事:

首先声明的依赖:

//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文件夹即可,完全没有必要。您应该始终使用适当的依赖管理,例如只需在您的构建脚本中声明它们,然后让 gradle 使用传递依赖项、正确的版本和依赖项冲突解决等下载它们。也删除此行:

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