如何在 gradle 中使用 kotlin-dsl 的多种口味?

How to use multiple flavors in gradle with kotlin-dsl?

它在 android gradle 构建脚本中。我在 gradle:

有多种口味
flavorDimensions "brand", "appVariant"
productFlavors {
    stage {
        dimension "appVariant"
    }
    prod {
        dimension "appVariant"
    }
    brand1 {
        dimension "brand"
    }
    brand2 {
        dimension "brand"
    }
}

如何使用 kotlin-dsl 重写它?

这会起作用:

flavorDimensions("brand", "appVariant")
productFlavors {
    create("var1") {
        setDimension("appVariant")
    }

    create("var2") {
        setDimension("appVariant")
    }

    create("brand1") {
        setDimension("brand")
    }

    create("brand2") {
        setDimension("brand")
    }
}