2

我对 Gradle 很陌生。当我做一个时,我的项目正在编译文件

./gradlew assembleDebug

但是当我尝试运行测试时它不会:

./gradlew connectedCheck

我得到(其中几个):

UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Lcom/facebook/AccessToken$SerializationProxyV1;
    at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:123)
    at com.android.dx.dex.file.DexFile.add(DexFile.java:163)
    at com.android.dx.command.dexer.Main.processClass(Main.java:490)
    at com.android.dx.command.dexer.Main.processFileBytes(Main.java:459)
    at com.android.dx.command.dexer.Main.access$400(Main.java:67)
    at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:398)
    at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:245)
    at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:131)
    at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:109)
    at com.android.dx.command.dexer.Main.processOne(Main.java:422)
    at com.android.dx.command.dexer.Main.processAllFiles(Main.java:333)
    at com.android.dx.command.dexer.Main.run(Main.java:209)
    at com.android.dx.command.dexer.Main.main(Main.java:174)
    at com.android.dx.command.Main.main(Main.java:91)

这是我的项目的结构:

main app depends on:
    compile 'com.android.support:support-v4:18.0.+'
    compile 'com.android.support:gridlayout-v7:18.0.+'
    compile 'com.google.code.gson:gson:1.7.2'
    compile 'com.jakewharton:butterknife:2.0.1'
    compile 'com.squareup.retrofit:retrofit:1.1.1'
    compile 'com.squareup:otto:1.3.4'
    compile 'com.squareup.okhttp:okhttp:1.2.0'
    compile project(':Library:mylib')

mylib depends on:
    compile 'com.android.support:support-v4:18.0.+'
    compile files('libs/facebooksdk.jar')
    compile files('libs/libGoogleAnalyticsV2.jar')

在此行之后,来自 mylib 的每个 jar 都会出现异常:

:Library:mylib:dexTest

任何想法?

4

2 回答 2

0

我遇到了同样的错误,但后面的消息already added:略有不同。这是关于重复的support-v4。我要解决的是:

compile('de.keyboardsurfer.android.widget:crouton:1.8.1') {
    exclude(group: 'com.google.android', module: 'support-v4')
}

希望它为您提供解决问题的新方向。

更新: 对不起,我没有仔细阅读你的问题。原来你的connectedCheck任务有问题。我的是跑步时gradle build。现在,当我运行时gradle connectedCheck,我遇到了同样的错误。我什至尝试过使用 IDE,但它们都不起作用。

实际上这里也有关于它的讨论https://code.google.com/p/android/issues/detail?id=61429。由于注释 #8,如果您移动到应用程序文件夹并运行上述任务,您可以管理。假设app文件夹是app-project/app,libs被放入app-projecct/libraries/my-lib-1。以前,我跑进去app-project失败了。

希望能修好。

于 2013-11-27T07:19:37.973 回答
0

多次引用库时会发生已添加的错误。我要做的是将编译项目设置为应用程序中的第一个编译元素并删除重复的支持库:

app depends on:
compile project(':Library:mylib')
compile 'com.google.code.gson:gson:1.7.2'
compile 'com.jakewharton:butterknife:2.0.1'
compile 'com.squareup.retrofit:retrofit:1.1.1'
compile 'com.squareup:otto:1.3.4'
compile 'com.squareup.okhttp:okhttp:1.2.0'


lib depends on:
compile 'com.android.support:support-v4:18.0.+'
compile files('libs/facebooksdk.jar')
compile files('libs/libGoogleAnalyticsV2.jar')
于 2013-08-22T14:22:25.847 回答