繁体   English   中英

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

[英]Android flavor+build type specific dependencies

我的build.gradle文件中包含stagingstableproduction以及默认构建类型debugrelease 对于其中的每一个,我都有不同的 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.

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