简体   繁体   English

gradle如何处理具有不同支持库v4版本的多个模块?

[英]How does gradle handle multi modules with different support library v4 revisions?

I have an Android project which depends on different modules and each modules depends on different revision of the android support-v4 library 我有一个Android项目,它依赖于不同的模块,每个模块依赖于android support-v4库的不同版本

1) My app also depends on the latest android support-v4 library (revision 21) so in this build.gralde I put a line like that: 1)我的应用程序还依赖于最新的android support-v4库(修订版21)所以在这个build.gralde中我放了一行:

dependencies {
            compile 'com.android.support:support-v4:21.0.0'
        }

2) Facebook SDK (v.3.15) module that also depends on the android support library v4, but revision 13 and its build.gradle file says: 2)Facebook SDK(v.3.15)模块也依赖于android支持库v4,但是版本13及其build.gradle文件说:

dependencies {
        compile 'com.android.support:support-v4:13.0.+'
        compile files('../libs/bolts.jar')
    }

3) and one more module that, we can call Module3 in that case, also depends on the support-v4 but with a different revision than the other modules, like that: 3)还有一个模块,在这种情况下我们可以调用Module3,也取决于support-v4但是与其他模块的修订版本不同,例如:

dependencies {
        compile 'com.android.support:support-v4:19.0.+'
        compile files('../libs/bolts.jar')
    }

Questions: 问题:

1) How does gradle handle different support-v4 library revisions? 1)gradle如何处理不同的support-v4库修订版?

2) What does it do exactly? 2)它究竟做了什么?

3) What does it mean in terms of apk size? 3)就apk大小而言,它是什么意思?

In this case Gradle will fail the build (tested on my skin and I did not find other solutions) "Unfortunately" you have to use the same version of support on any module. 在这种情况下,Gradle将失败构建(在我的皮肤上测试,我没有找到其他解决方案)“不幸的是”你必须在任何模块上使用相同版本的支持。

From docs.gradle.com : 来自docs.gradle.com

Gradle offers the following conflict resolution strategies: Gradle提供以下冲突解决策略:

  • Newest : The newest version of the dependency is used. 最新 :使用最新版本的依赖项。 This is Gradle's default strategy, and is often an appropriate choice as long as versions are backwards-compatible. 这是Gradle的默认策略,只要版本向后兼容,它通常是一个合适的选择。

  • Fail : A version conflict results in a build failure. 失败 :版本冲突导致构建失败。 This strategy requires all version conflicts to be resolved explicitly in the build script. 此策略要求在构建脚本中显式解决所有版本冲突。 See ResolutionStrategy for details on how to explicitly choose a particular version. 有关如何明确选择特定版本的详细信息,请参阅ResolutionStrategy。

While the strategies introduced above are usually enough to solve most conflicts, Gradle provides more fine-grained mechanisms to resolve version conflicts: 虽然上面介绍的策略通常足以解决大多数冲突,但Gradle提供了更细粒度的机制来解决版本冲突:

  • Configuring a first level dependency as forced . 将第一级依赖关系配置为强制 This approach is useful if the dependency in conflict is already a first level dependency. 如果冲突中的依赖关系已经是第一级依赖,则此方法很有用。 See examples in DependencyHandler . 请参阅DependencyHandler中的示例。

  • Configuring any dependency (transitive or not) as forced . 将任何依赖项(传递或不传递)配置为强制 This approach is useful if the dependency in conflict is a transitive dependency. 如果冲突中的依赖性是传递依赖性,则此方法很有用。 It also can be used to force versions of first level dependencies. 它还可用于强制第一级依赖项的版本。 See examples in ResolutionStrategy 请参阅ResolutionStrategy中的示例

  • Dependency resolve rules are an incubating feature introduced in Gradle 1.4 which give you fine-grained control over the version selected for a particular dependency. 依赖性解析规则是Gradle 1.4中引入的一种孵化功能,它可以对为特定依赖项选择的版本进行细粒度控制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM