buildConfigField depending on flavor + buildType

前端 未结 2 544
离开以前
离开以前 2020-12-05 08:19

I\'m trying to define a buildConfigVariable depending on the flavor + buildType. Ideally, this is what I want

productFlavors {
            


        
2条回答
  •  隐瞒了意图╮
    2020-12-05 08:41

    Edit2: The version after 0.14.2 will allow doing this:

    applicationVariants.all { variant ->
        variant.buildConfigField "int", "VALUE", "1"
    }
    

    So you'd be able to do something like this (to match the original question):

    applicationVariants.all { variant ->
        variant.buildConfigField "String", "WS_API_KEY", variant.productFlavors.get(0).name + '_' + variant.buildType.name
    }
    

    Edit: it's not currently possible. The API is missing for this. Bug: https://code.google.com/p/android/issues/detail?id=67416

    Try this:

    applicationVariants.all { variant ->
        variant.mergedFlavor.buildConfigField "String", "NAME", '"VALUE"'
    }
    

提交回复
热议问题