![](/img/trans.png)
[英]Bazel - Get current OS and CPU type as variables to be used in build rules
[英]build gradle variables to be used in code depending on flavor AND build type
有沒有辦法在我的代碼中使用build.gradle中的變量,這取決於flavor AND buildType?
在這個例子中: 是否可以在Gradle中聲明一個可用於Java的變量? 新資源值僅取決於其是否為調試版本或發布版本類型。
我想擁有的是每個可能的buildVariant的一個變量。
像這樣的東西:
flavor1Debug => resValue "string", "app_name", "App 1 Debug"
flavor1Release => resValue "string", "app_name", "App 1"
flavor2Debug => resValue "string", "app_name", "App 2 Debug"
flavor2Release => resValue "string", "app_name", "App 2"
有沒有一種很好的方法可以通過build.gradle或其他不包含switch或if語句的方式來實現這一點?
在您的應用的build.gradle中,您可以實現此目的的一種方法是:
buildTypes {
debug {
productFlavors.flavor1.buildConfigField "String", "app_name", "\"App 1 Debug\""
productFlavors.flavor2.buildConfigField "String", "app_name", "\"App 2 Debug\""
}
release {
productFlavors.flavor1.buildConfigField "String", "app_name", "\"App 1\""
productFlavors.flavor2.buildConfigField "String", "app_name", "\"App 2\""
}
}
請注意,您需要在buildType之前定義productFlavors {}塊。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.