我想將一個大的應用程序從Ant遷移到Gradle。 由於應用程序已經(錯誤地)創建爲多個庫,第一遷移將保持相同的模塊(將在第二步驟中重構),它很可能會在該結構中結束:Android Gradle應用程序和庫的jar衝突
-- Project/ |-- App/ |-- libs/ |-- src/... |-- build.gradle |-- Module1/ |-- libs/ |-- lib1.jar |-- lib2.jar |-- src/... |-- build.gradle |-- Module2/ |-- libs/ |-- lib2.jar |-- lib3.jar |-- src/... |-- build.gradle build.gradle settings.gradle
該應用的build.gradle是這樣的:
... apply plugin: 'com.android.application' dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:support-v4:20.0.0' compile 'com.android.support:appcompat-v7:20.0.0' compile project(':Module1') compile project(':Module2') } ...
,然後將每個模塊的build.gradle將是這樣的:
... apply plugin: 'com.android.library' dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:support-v4:20.0.0' compile 'com.android.support:appcompat-v7:20.0.0' } ...
每模塊編譯正確,但是在構建APK時發生問題,因爲lib2.jar被複制了2次,導致出現錯誤:
錯誤:Gradle:執行任務':app:packageDebug'失敗。
Duplicate files copied in APK META-INF/ASL2.0 and then the path to the 2 JARs.
如何讓Gradle在每個模塊構建APK時不多次拷貝相同的JAR? 現在,即使我將來也不能將依賴關係移動到Maven中央回購站。 也許在父應用程序中添加所有庫?它對我來說看起來不是很好......在這種情況下,我如何在build.gradle模塊中指定這些依賴關係?
您是否試過這種方式:tools.android.com/tech-docs/new-build-system/tips(最後一段)? – sandrstar 2014-12-29 12:31:09