我的 Android 应用程序中有两个模块:app
和 library
。 app
依赖library
在 library
我想使用 AndroidAnnotations 4.0.0
在 app
中,我目前想使用 AndroidAnnotations 3.2.2
,因为将其升级到 4.0.0 需要进行大量更改,因为他们已经对其进行了相当大的更改很多,我现在没有时间这样做。
但是,自从我升级library
以使用AndroidAnnotations 4.0.0
后,app
中AndroidAnnotations
的使用> 表现得像第 4 版,而不是第 3 版,这让我觉得 Gradle 真的很聪明,忽略了 app
的第 3 版,并为两个模块使用第 4 版。
如何在 gradle 中强制使用两个不同版本的依赖项?
最佳答案
使用 force 强制使用依赖版本。命令
build.gradle
(应用程序):
dependencies {
compile ('com.squareup.okhttp:okhttp:2.4.0') {
force = true
}
...
}
build.gradle
(库):
dependencies {
compile 'com.squareup.okhttp:okhttp:2.3.0'
...
}
如果链接失效,这里是文档的摘录:
Allows forcing certain versions of dependencies, including transitive dependencies. Appends new forced modules to be considered when resolving dependencies.
It accepts following notations:
String in a format of: 'group:name:version', for example: 'org.gradle:gradle-core:1.0' instance of ModuleVersionSelector any collection or array of above will be automatically flattened
关于android - 如何通过 Gradle 使 Android Studio 中的两个不同模块使用同一库的不同版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37114961/