gpt4 book ai didi

Android 风格+构建类型特定的依赖项

转载 作者:行者123 更新时间:2023-11-30 04:58:09 26 4
gpt4 key购买 nike

我的 build.gradle 文件、stagingstableproduction 以及默认构建类型 debugrelease。对于其中的每一个,我都有不同的 AAR 文件,例如,我有一个要用于 stagingDebug 的 AAR,一个用于 stagingRelease 的 AAR,以及stableDebug 和所有其他变体。

我可以使用 releaseImplementation ('xxxx@aar')stagingImplementation ('yyyy@aar'),但我无法使用 stagingReleaseImplementation ('zzzzz@aar')

有什么方法可以使用 flavor+build 类型特定的依赖项吗?

最佳答案

一个解决方案是在您的顶级 build.gradle 文件中定义一个变量:

project.ext.BuildCmdLine = "Release"

android {
applicationVariants.all { variant ->
project.ext.BuildCmdLine= variant.buildType.name // Sets the current build type
}
}

然后在你模块的build.gradle文件中,你可以根据project.ext.BuildCmdLine设置你想使用的依赖:

dependencies {

if (project.BuildCmdLine == "Release") {
api(name: 'yourlib-release', ext: 'aar')
} else {
api(name: 'yourlib-debug', ext: 'aar')
}
}

关于Android 风格+构建类型特定的依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58768955/

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