如何将特定变量添加到不同的调试和发布风格
Posted
技术标签:
【中文标题】如何将特定变量添加到不同的调试和发布风格【英文标题】:How to add specific variable to a single flavor different for debug and release 【发布时间】:2021-01-13 08:09:01 【问题描述】:一些帮助找到如何做到这一点: 我只想为 1 种口味创建一些 resValue,这些 resvalue 必须根据构建类型而有所不同 (为了安全起见,如果我稍后添加 buildType 并忘记按照我的方式管理它,则会产生错误)
productFlavors
lite
dimension "default"
applicationIdSuffix ".lite"
//// HOW TO DO THIS ?
if(buildTypes.debug)
def banner = "my test id"
resValue "string", "ad_view_banner_footer", banner
else if(buildTypes.release)
def banner_footer = "my real id"
resValue "string", "ad_view_banner_footer", banner_footer
else "GENERATE ERROR UNKNOWN BUILDTYPES"
/// Thanks
full
dimension "default"
applicationIdSuffix ".full"
谢谢
【问题讨论】:
【参考方案1】:所以我自己回答。混合使用我在这里和那里找到的东西:
flavorDimensions "default"
productFlavors
lite
dimension "default"
applicationIdSuffix ".lite"
def application_id = "my application id"
manifestPlaceholders = [ad_view_application_id:application_id]
full
dimension "default"
applicationIdSuffix ".full"
variantFilter variant ->
if(variant.name.startsWith(productFlavors.lite.name))
def buildType;
def ad_view_banner_footer;
if(variant.buildType.name == buildTypes.release.name)
buildType = buildTypes.release;
ad_view_banner_footer = "my banner id"
else if(variant.buildType.name == buildTypes.debug.name)
def banner = "ca-app-pub-3940256099942544/6300978111"
def interstitial = "ca-app-pub-3940256099942544/1033173712"
def interstitial_video = "ca-app-pub-3940256099942544/8691691433"
def rewarded_video = "ca-app-pub-3940256099942544/5224354917"
def native_advanced = "ca-app-pub-3940256099942544/2247696110"
def native_advanced_video = "ca-app-pub-3940256099942544/1044960115"
buildType = buildTypes.debug;
ad_view_banner_footer = banner;
else throw new Exception("unknown buildType");
buildType.resValue "string", "ad_view_banner_footer", ad_view_banner_footer
【讨论】:
以上是关于如何将特定变量添加到不同的调试和发布风格的主要内容,如果未能解决你的问题,请参考以下文章
加载不同的 .html 文件时如何访问特定的 $scope 变量?
如何为不同的风格和构建类型设置 applicationid?