2013-08-22 35 views
2

我是Gradle的新手。我的項目是編制文件時,我做了當使用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的每個罐子的異常來自此行後:

:Library:mylib:dexTest 

任何想法?

回答

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') 
+0

做了所有這些,仍然得到這些錯誤。我很確定它與這些罐子無關: -/ –

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。由於the comment #8,如果您移動到應用程序文件夾並在任務之上運行,則可以進行管理。假設app文件夾是app-project/app,則將這些庫存放在app-projecct/libraries/my-lib-1中。以前,我跑在​​並失敗。

希望修復。

+0

這不適用於jar文件我認爲: -/ –

+0

請看看我上面的更新。 –

相關問題