为特定的风格和buildType定义buildconfigfield [英] Define buildconfigfield for an specific flavor AND buildType
本文介绍了为特定的风格和buildType定义buildconfigfield的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
def BOOLEAN =boolean
def VARIABLE =VARIABLE
def TRUE =true
def FALSE =false
VANILLA {
debug {
buildConfigField BOOLEAN,VARIABLE,FALSE
}
release {
buildConfigField BOOLEAN,VARIABLE,TRUE
}
}
巧克力{
buildConfigField BOOLEAN,VARIABLE,FALSE
我有一个错误,所以我想调试和发布技巧不起作用。可以这样做吗?
解决方案
循环变体并检查它们的名称:
productFlavors {
vanilla {}
巧克力{}
}
applicationVariants.all {variant - > ;
println(Iterating variant:+ variant.getName())
if(variant.getName()==chocolateDebug){
variant.buildConfigFieldboolean,VARIABLE ,true
} else {
variant.buildConfigFieldboolean,VARIABLE,false
}
}
I have 2 flavors, lets say Vanilla and Chocolate. I also have Debug and Release build types, and I need Vanilla Release to have a field true, while the other 3 combinations should be false.
def BOOLEAN = "boolean"
def VARIABLE = "VARIABLE"
def TRUE = "true"
def FALSE = "false"
VANILLA {
debug {
buildConfigField BOOLEAN, VARIABLE, FALSE
}
release {
buildConfigField BOOLEAN, VARIABLE, TRUE
}
}
CHOCOLATE {
buildConfigField BOOLEAN, VARIABLE, FALSE
}
I'm having an error, so I guess the debug and release trick doesnt work. It is possible to do this?
解决方案
Loop the variants and check their names:
productFlavors {
vanilla {}
chocolate {}
}
applicationVariants.all { variant ->
println("Iterating variant: " + variant.getName())
if (variant.getName() == "chocolateDebug") {
variant.buildConfigField "boolean", "VARIABLE", "true"
} else {
variant.buildConfigField "boolean", "VARIABLE", "false"
}
}
这篇关于为特定的风格和buildType定义buildconfigfield的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文