[英]Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files are defined
[英]Intellij: Avoiding 'Multiple Dex Files Defined'
問題:
到目前為止,我一直在使用Gradle處理我的所有依賴關系,並且似乎可以處理其他Gradle模塊之間的所有重復依賴關系。 但是,當jar中存在重復的依賴項時,情況似乎並非如此。
題:
考慮到我可以控制jar中的內容,使用Gradle處理這些依賴項沖突的最佳實踐是什么:
不要在jar中包含任何外部依賴項,請使用build.gradle
將其包含在項目本身中
將所有外部依賴項包含在jar中,通過從項目build.gradle
其刪除,以消除重復build.gradle
。 ( 注意:這似乎不可擴展,例如,如果罐子本身之間存在重復項。)
更好的東西(希望可以自動處理)
編輯: build.gradle
文件:
apply plugin: 'com.android.application'
android {
signingConfigs {
release { ... }
debug { ... }
}
compileSdkVersion 19
buildToolsVersion '19.1.0'
defaultConfig { ... }
buildTypes {
release { ... }
debug { ... }
}
sourceSets {
instrumentTest.setRoot('tests')
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:20.0.0'
compile project(':jarModule')
}
導入具有本地應用程序中也具有依賴性的外部jars
,您可以執行以下兩項操作:
jar
依賴項轉換為Gradle依賴項,並排除依賴項 例如:
testCompile('org.robospock:robospock:0.5.0') {
exclude module: "groovy-all" // <-- excludes groovy from robo spock
}
要么
.jar
依賴項 例如,對於您與Gson
的情況:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:20.0.0'
compile project(':jarModule')
// compile 'com.google.code.gson:gson:2.3.1' // <-- removed
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.