2016-05-09 48 views
1

我的Android应用程序中有两个模块:applibraryapp取决于library如何使Android Studio中的两个不同模块通过Gradle使用同一个库的不同版本

library我想用AndroidAnnotations 4.0.0

app我想目前使用AndroidAnnotations 3.2.2,因为它升级到4.0.0将要求改变一个庞大的,因为他们已经改变了它相当很多,我现在没有时间去做这件事。

然而,自从我升级library使用AndroidAnnotations 4.0.0AndroidAnnotationsapp的行为的使用,因为它是版本4,没有第3版,这让我觉得摇篮真的很聪明,忽略第3版app和使用版本4为两个模块。

如何在gradle中强制使用两个不同版本的依赖项?

+0

你不能有两个不同的版本,因为还会有命名空间冲突。唯一可行的方法是自己重新打包其中一个版本,并更改​​类的包名,以免发生冲突。 –

回答

0

强制使用的依赖版本对另一使用force命令

build.gradle(APP):

dependencies { 
    compile ('com.squareup.okhttp:okhttp:2.4.0') { 
     force = true 
    } 
    ... 
} 

build.gradle(库):

dependencies { 
    compile 'com.squareup.okhttp:okhttp:2.3.0' 
    ... 
} 

这里是摘自docs如果链接无效:

允许强制某些版本的依赖关系,包括可传输的 依赖关系。附加新的强制模块,以便在解决依赖关系时考虑 。

它接受下面的符号:

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 
相关问题