本文介紹了排除特定的構建變體的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我有兩種默認的構建類型:debug/release 和幾個風格:prod/dev.
I have the two default build types: debug / release and a couple of flavors: prod / dev.
現在我想排除構建變體 dev-release,但保留所有其他可能的組合.有沒有辦法做到這一點?
Now I want to exclude the build variant dev-release, but keep all other possible combinations. Is there a way to achieve this?
推薦答案
變體過濾器
使用 gradle android 插件的 variantFilter 將某些組合標記為忽略.這是官方文檔中的一個示例,適用于風味維度并展示如何使用它:
Variant filter
Use the variantFilter of the gradle android plugin to mark certain combinations as ignored. Here is an example from the official documentation that works with flavor dimensions and shows how it can be used:
android {
...
buildTypes {...}
flavorDimensions "api", "mode"
productFlavors {
demo {...}
full {...}
minApi24 {...}
minApi23 {...}
minApi21 {...}
}
variantFilter { variant ->
def names = variant.flavors*.name
// To check for a certain build type, use variant.buildType.name == "<buildType>"
if (names.contains("minApi21") && names.contains("demo")) {
// Gradle ignores any variants that satisfy the conditions above.
setIgnore(true)
}
}
}
正如評論所說,您也可以像這樣檢查 buildType:
As the comment says, you can also check the buildType like so:
android {
variantFilter { variant ->
def names = variant.flavors*.name
if(variant.buildType.name == 'release' && names.contains("myforbiddenflavor")) {
setIgnore(true)
}
}
}
這篇關于排除特定的構建變體的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!