gpt4 book ai didi

android - 为多个变体定义依赖关系

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:53:56 24 4
gpt4 key购买 nike

假设我们有四种构建类型:调试、质量检查、测试版和发布。

我们可以像这样定义特定变体的依赖关系:

dependencies {
// These dependencies are only included for debug and qa builds
debugCompile 'com.example:lib:1.0.0'
qaCompile 'com.example:lib:1.0.0'
}

有没有办法在不重复 Artifact 描述符的情况下为多个变体编译这些依赖项?

例如,我想做这样的事情:

dependencies {
internalCompile 'com.example:lib:1.0.0'
}

internalCompile 将指定库包含在 debugqa 构建中。

我相信解决方案在于定义一个新的 Gradle configuration ,但是如果我创建一个 internalCompile 配置,我不确定如何确保这些依赖项只为 qadebug 构建编译。

最佳答案

extendsFrom

The names of the configurations which this configuration extends from. The artifacts of the super configurations are also available in this configuration.

configurations {
// debugCompile and qaCompile are already created by the Android Plugin
internalCompile
}

debugCompile.extendsFrom(internalCompile)
qaCompile.extendsFrom(internalCompile)

dependencies {
//this adds lib to both debugCompile and qaCompile
internalCompile 'com.example:lib:1.0.0'
}

或者:

您可以创建 Artifact 描述符的集合并将其用于多种配置。

List internalCompile = ["com.example:lib:1.0.0",
"commons-cli:commons-cli:1.0@jar",
"org.apache.ant:ant:1.9.4@jar"]

List somethingElse = ['org.hibernate:hibernate:3.0.5@jar',
'somegroup:someorg:1.0@jar']

dependencies {
debugCompile internalCompile
qaCompile internalCompile, somethingElse
}

关于android - 为多个变体定义依赖关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34907948/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com