問題描述
我在項目中包含的庫遇到了一些問題:一開始,這只是一個相互沖突的依賴問題,我通過排除來解決support-v4
是常用的共享模塊.
I'm running into some trouble with a library I included into my project:
At the beginning it was just a conflicting dependencies issue that I resolved by excluding
support-v4
which is the commonly shared module.
問題在于,其中一個 lbsLib-release
似乎是在開發(fā)人員構建之前使用根項目內的普通 .jar
文件構建的.
The problem is that one of those lbsLib-release
seems to have been built with a plain .jar
file inside of the root project before the developer build.
通過運行 ./gradlew app:dependencies
我驗證了構建圖中沒有引用依賴項.
By running ./gradlew app:dependencies
I verified that the dependency is not referenced in the build graph.
我發(fā)現(xiàn)這個 support-v4
嵌入到 classes.jar
中在:app/build/intermedites/exploded-aar/MyQaaAndroid/lbsLib-release/unspecified/classes.jar/
,如下圖所示:
And I found this support-v4
embedded into the classes.jar
located
at : app/build/intermedites/exploded-aar/MyQaaAndroid/lbsLib-release/unspecified/classes.jar/
as you can see on the picture below:
我不能自己重建項目,因為它不是一個開源的lib,所以有兩個問題:
I can't rebuild the project myself because it is not an open-sourced lib, so there is two problem:
如果我將
compile 'com.android.support:support-v4:18.0.+'
添加到build.gradle
一個multiple dex文件
在構建時拋出錯誤,因此庫被引用了兩次.
If I add
compile 'com.android.support:support-v4:18.0.+'
to thebuild.gradle
amultiple dex file
error is thrown at build time so the library is referenced twice.
UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexException: Multiple dex files define Landroid/support/v4/app/BackStackState;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
at com.android.dx.command.dexer.Main.run(Main.java:246)
at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.Main.main(Main.java:106)
`
如果我刪除所有需要 support-v4
的庫,它會在應用程序運行時引發(fā)缺少依賴項錯誤.
If I remove all libs which require support-v4
it throws a missing dependencies error at the application runtime.
所以我想知道是否可以從構建中排除這個 .jar
文件或使其他庫依賴于 lbsLib-release
嵌入 support-v4
.jar
.
So I would like to know if it is possible to exclude this .jar
file from the build or to make the others libs depends on the lbsLib-release
embedded support-v4
.jar
.
compile (project(':lbsLib-release')) {
exclude module: 'support-v4'
}
compile ('com.sothree.slidinguppanel:library:2.0.4'){
exclude module: 'support-v4'
}
compile('com.google.android.gms:play-services:6.5.87') {
exclude module: 'support-v4'
}
推薦答案
嘗試使用 resolutionStrategy
(API 參考) 在根 build.gradle
.
Try to use resolutionStrategy
(API reference) at root build.gradle
.
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
}
}
allprojects {
repositories {
jcenter()
}
configurations.all((Closure) {
resolutionStrategy {
force 'com.android.support:support-v4:21.0.2' // your version of support library
}
})
}
這篇關于Gradle 排除或添加硬包含在庫 classes.jar 中的 JAR 文件的引用的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!