本文介紹了為特定風味和 buildType 定義 buildconfigfield的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我有 2 種口味,比如說香草和巧克力.我也有 Debug 和 Release 構建類型,我需要 Vanilla Release 的字段為 true,而其他 3 個組合應該為 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的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!