android - 如何通过 Gradle 使 Android Studio 中的两个不同模块使用同一库的不同版本

标签 android gradle

我的 Android 应用程序中有两个模块:applibraryapp 依赖library

library 我想使用 AndroidAnnotations 4.0.0

app 中,我目前想使用 AndroidAnnotations 3.2.2,因为将其升级到 4.0.0 需要进行大量更改,因为他们已经对其进行了相当大的更改很多,我现在没有时间这样做。

但是,自从我升级library以使用AndroidAnnotations 4.0.0后,appAndroidAnnotations的使用> 表现得像第 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/

相关文章:

android - React-Native Android Studio 项目构建失败显示 "Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0."

Eclipse 中的 Gradle 未在 Eclipse IDE 中显示外部依赖项源和 java 文档

gradle - Gradle:为传递依赖项配置存储库

unit-testing - 使用 testImplementation 项目在另一个模块中测试时未解析的引用(:deepestModule)

android - 如何隐藏自定义选项卡的 URL?

c# - Java "events"- 只不过是接口(interface)。当它只是一个普通的接口(interface)和实现该接口(interface)的类时,为什么还要假装它是事件呢?

android - 苹果开发商导出合规

安卓 : width and height must be > 0 for recycler view when Converting to Bitmap

android - 检查网络连接android

gradle - 为什么@DisplayName 在 JUnit 5 中对我不起作用?