[英]Android flavor+build type specific dependencies
我的build.gradle
文件中包含staging
、 stable
和production
以及默认构建类型debug
和release
。 对于其中的每一个,我都有不同的 AAR 文件,例如,我有一个要用于stagingDebug
的 AAR,另一个用于stagingRelease
的 AAR,以及stableDebug
和所有其他变体。
我可以使用releaseImplementation ('xxxx@aar')
和stagingImplementation ('yyyy@aar')
,但我无法使用stagingReleaseImplementation ('zzzzz@aar')
有什么方法可以使用风味+构建类型特定的依赖项吗?
一种解决方案是在您的顶级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')
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.