Android studio gradle flavor dimensions build varients not working correctly

前端 未结 1 907
梦如初夏
梦如初夏 2020-12-29 23:48

I have two dimensions of an app, call then green and blue. There will only be these two dimensions but an unlimited number of product flavors. This is the way I\'m setting i

相关标签:
1条回答
  • 2020-12-30 00:26

    I think you misunderstood the concept of flavorDimension.

    A flavorDimension is something like a flavor category and every combination of a flavor from each dimension will produce a variant.

    In your case, you must define one flavorDimension named "type" and another dimension named "organization". It will produce, for each flavor in the dimension "organization" all possible "type" (or the dual formulation : for each "type" it will produce a variant for each organization).

    The flavor dimensions define the cartesian product that will be used to produce variants.


    EDIT : I'll try to illustrate with pseudo-gradle code:

    Let's define some "type" : bronze, silver and gold

    Let's define some organizations : customerA, customerB, customerC

    All those are productFlavors, but they belong to 2 different dimensions:

    flavorDimensions("type_line", "organization")
    productFlavors {
    
        gold {
            ...
            dimension = "type_line"
        }
        silver {
            ...
            dimension = "type_line"
        }
        bronze {
             ...
            dimension = "type_line"
        }
    
         customerA {
            ...
            dimension = "organization"
        }
        customerB {
            ...
            dimension = "organization"
        }
        customerC {
             ...
            dimension = "organization"
        }
    
    }
    

    This config will produce 18 (3*3*2) variants (if you have the 2 standard build types : debug and release) :

    gold-customerA-debug ; gold-customerA-release ; gold-customerB-debug ; gold-customerB-release ; gold-customerC-debug ; gold-customerC-release ;

    silver-customerA-debug ; silver-customerA-release ; silver-customerB-debug ; silver-customerB-release ; silver-customerC-debug ; silver-customerC-release ;

    ... (the same for bronze)

    Note that the name of the dimension is totally arbitrary and have no impact on variant names.

    Flavor dimensions are very powerful, but if you use too much of them : it results in an exponential explosion of the number of variants (a post build clean-up task may be useful to delete useless or non-sense variant)

    0 讨论(0)
提交回复
热议问题