Android的工作室+摇篮:java.lang.IllegalArgumentException异常 [英] Android Studio + Gradle: java.lang.IllegalArgumentException

查看:248
本文介绍了Android的工作室+摇篮:java.lang.IllegalArgumentException异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的摇篮项目,并申报的build.gradle我的依赖关系:

I have my project with Gradle and declare my dependencies on build.gradle:

dependencies {
compile 'com.android.support:support-v4:18.0.0'
compile 'org.springframework.android:spring-android-rest-template:1.0.1.RELEASE'
compile 'org.springframework.android:spring-android-auth:1.0.1.RELEASE'
compile 'org.springframework.android:spring-android-core:1.0.1.RELEASE'
compile 'org.roboguice:roboguice:2.0'

}

与摇篮构建做工精细,但是当我运行一个项目下面的错误是扔在编译阶段:

Build with Gradle work fine, but when a run my project a following error is throw on compilation phase:

Gradle: UNEXPECTED TOP-LEVEL EXCEPTION:
Gradle: java.lang.IllegalArgumentException: already added: Lorg/springframework/util/FileCopyUtils;
Gradle: at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:122)
Gradle: at com.android.dx.dex.file.DexFile.add(DexFile.java:161)

我用摇篮1.8。

I use Gradle 1.8.

推荐答案

它看起来像多库包括核心库文件;我得到一个稍微不同的异常,当我做一个样品的情况下,但它是相同的原因。如果我打开外部库标签来看看什么罐子它的使用,我看到的弹簧Android的核心弹簧芯,然后如果我打开这些了,看看有什么类在他们,我看到都包含 org.springframework.core.Error codeD (这是重复类在我测试用例)。

It looks like multiple libraries are including the core library files; I get a slightly different exception when I make a sample case, but it's the same cause. If I open up the External Libraries tab to look at what jars it's using, I see spring-android-core and spring-core, and if I open those up to see what classes are in them, I see that both contain org.springframework.core.ErrorCoded (which is the duplicate class in my test case).

你不包括弹簧芯的直接;它的到来在从弹簧Android的AUTH 库的传递性依赖(如果我只包括这两个图书馆和省略的弹簧Android的休息模板我仍然得到错误)。我试图通过在中央Maven的POM中文件定义挖掘,试图证明为什么它的发生,但我不知道我可以给你一个没有很多像蜂窝状的解释,所以我会留在安静这一方面;-)但我不会缺乏了解获得在试图解决这个问题的方式。如果你告诉弹簧Android的身份验证的依赖,以排除弹簧芯,它的伎俩:

You're not including spring-core directly; it's coming in as a transitive dependency from the spring-android-auth library (if I include just those two libraries and omit spring-android-rest-template I still get the error). I tried digging through the pom file definitions in Maven Central to try to prove why it's happening, but I'm not sure I could give you an explanation that didn't have a lot of holes in it, so I'll stay quiet on that front ;-) But I won't lack of understanding get in the way of trying to fix the problem. If you tell the spring-android-auth dependency to exclude spring-core, it does the trick:

dependencies {
    ...
    compile 'org.springframework.android:spring-android-rest-template:1.0.1.RELEASE'
    compile('org.springframework.android:spring-android-auth:1.0.1.RELEASE') {
        exclude module: 'spring-core'
    }
    compile 'org.springframework.android:spring-android-core:1.0.1.RELEASE'
}

我也遇到了这个错误:

I also came across this error:

Execution failed for task ':app:packageDebug'.
> Duplicate files copied in APK META-INF/notice.txt
File 1: /Users/sbarta/.gradle/caches/modules-2/files-2.1/org.springframework.android/spring-android-auth/1.0.1.RELEASE/f43faebbf90aef324979a81a4f5eee1e3b95191f/spring-android-auth-1.0.1.RELEASE.jar
File 2: /Users/sbarta/.gradle/caches/modules-2/files-2.1/org.springframework.android/spring-android-auth/1.0.1.RELEASE/f43faebbf90aef324979a81a4f5eee1e3b95191f/spring-android-auth-1.0.1.RELEASE.jar

所以我只好跟着在<一的说明href=\"http://stackoverflow.com/questions/20673625/android-gradle-plugin-0-7-0-duplicate-files-during-packaging-of-apk/20675331#20675331\">Android摇篮插件0.7.0:&QUOT; APK&QUOT的包装过程中重复的文件; 来排除一些包装META-INF /文件,我说:

so I had to follow the instructions at Android Gradle plugin 0.7.0: "duplicate files during packaging of APK" to exclude some META-INF/ files from packaging, and I added:

android {
    ...
    packagingOptions {
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license.txt'
    }
}

这篇关于Android的工作室+摇篮:java.lang.IllegalArgumentException异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆