Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use of flavour dimensions in build.gradle in android studio

We can build multiple variants of application using product flavours field in build gradle. Why flavour dimension? And it is made compulsory with error message, "All flavours should now belong to flavour dimension"

If it has sensible uses, How and where can we differentiate configuration for different flavour dimensions?

All other blogs and posts I referred didn't give me satisfying answers and most tell me "you won't need it". Please throw some light.

like image 660
LincyTonita Avatar asked Jul 06 '18 12:07

LincyTonita


1 Answers

I'd best describe flavour dimensions as a way of grouping flavours.

The one use case I can think of is this.

  • You have a free and paid flavour under a dimension of tier.

  • You have a test and prod flavour which point to different backends under a dimension of environment.

When you assemble all you end up with a version for each tier and environment so you can test a free/test version, free/prod version etc.

You don't need to inspect the dimension, just put whatever variables/ conditional code against the flavour as has always been the case.

An example using multiple dimensions

,,,
flavorDimensions "tier", "env"

productFlavors {
    paid {
        dimension "tier"
        ... add variables here
    }

    free {
        dimension "tier"
        versionName = android.defaultConfig.versionName + " free"
        ... add variables here
    }

    test {
         dimension "env"
         ... add variables here
    }

    prod {
         dimension "env"
         ... add variables here
    }
}
...
like image 156
CodeChimp Avatar answered Oct 17 '22 17:10

CodeChimp