2015-01-20 109 views
5

我嘗試編譯模塊,其依賴關係樹看起來像Gradle的衝突解決方案不適用於Android項目?

+--- com.squareup.burst:burst-junit4:1.0.2 
| +--- com.squareup.burst:burst:1.0.2 
| \--- junit:junit:4.11 -> 4.12 
|   \--- org.hamcrest:hamcrest-core:1.3 
+--- com.android.support.test.espresso:espresso-core:2.0 
| +--- com.squareup:javawriter:2.1.1 
| +--- org.hamcrest:hamcrest-integration:1.1 
| | \--- org.hamcrest:hamcrest-core:1.1 -> 1.3 
| +--- org.hamcrest:hamcrest-library:1.1 
| | \--- org.hamcrest:hamcrest-core:1.1 -> 1.3 
| +--- com.android.support.test.espresso:espresso-idling-resource:2.0 
| +--- com.android.support.test:testing-support-lib:0.1 
| | \--- junit:junit-dep:4.10 
| |   \--- org.hamcrest:hamcrest-core:1.1 -> 1.3 
| +--- com.google.code.findbugs:jsr305:2.0.1 
| +--- javax.annotation:javax.annotation-api:1.2 
| \--- org.hamcrest:hamcrest-core:1.1 -> 1.3 
... 

正如你可以看到有一個hamcrest-core版本衝突,但gradle這個似乎認識到衝突並應用其默認「最新版本」戰略,正是我想要的。

然而,當嘗試(手動或通過Android Studio中)我得到

com.android.dex.DexException: Multiple dex files define Lorg/hamcrest/MatcherAssert; 

一些回答類似的問題建議exclude荷蘭國際集團的不必要的罐子運行assembleDebugTest,但我遇到了一堆類似的衝突,而且它變得有點失控。

爲什麼Gradle的默認衝突策略會自動刪除舊的jar? Android gradle插件是否抑制該功能?

+0

http://stackoverflow.com/questions/20989317/multiple-dex-files-define-landroid-support-v4-accessibilityservice-accessibility – 2015-01-21 01:45:34

+0

我確實看到了這一點,並且我理解了快速修復。我的問題是爲什麼Gradle的默認解析策略不能用於自動移除其中一個罐子,正如我期望閱讀[本文檔](http://www.gradle.org/docs/current/dsl/org)。 gradle.api.artifacts.ResolutionStrategy.html)。 – 2015-01-21 01:58:16

+0

可以嘗試使用-verbose構建...找到configurations.resolutionStrategy {}被調用的位置....如果未被調用,則提供您自己的實現。 – 2015-01-21 16:04:56

回答

8

一些更多的挖掘後,似乎問題是我的依賴關係樹包含hamcrest-core 1.3和1.1 hamcrest-integrationMatcherAssert被移動從hamcrest-integration這些版本之間hamcrest-core

所以gradle正在執行衝突解決方案,如記錄;我沒有想到的不同模塊之間只有一個衝突。

對所有三個hamcrest模塊強制使用1.3來解決這個問題。

+2

我該怎麼做 – 2015-09-17 15:27:53

+0

@ user1232726請參閱https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.ResolutionStrategy.html – 2015-09-17 19:06:30