Updated 24 October 2020
Build variant is used to create different version of application in single project. Each Build variant creates different versions of our app. Like, you wanna make any music application with two version, one is free and other one is paid.
Build variant is result of build type and product flavor.
Example:
Build type : debug, release
Product Flavor : first, second
Build Variant : firstDebug, firstRelease, secondDebug, secondRelease
Gradle creates every possible combination of build type and product flavor as build variant by default.
Build type defines in build.gradle files. Android Studio provides two type of build type.
1. debug
2. release
When we create any project in Android Studio, it automitacally creates build type for us. The debug build type doesn’t apprear in build file, Android Studio configures it with debuggable true. You can add debug block in build.gradle file and configure its setting.
Debug version is used for testing purpose. If you wanna create upload app on play store, you need to create releasable version.
Android Studio configure build type with debuggable true. If you wanna upload release version on play store, so you need to set it false in build.gradle in release block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
android { buildTypes { release { debuggable false minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } debug { debuggable true minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } |
For product flavor, we add block in build.gradle same as build type. The product flavors support the same properties as defaultConfig—this is because defaultConfig actually belongs to the ProductFlavor class. You can change any property of defaultConfig in product flavor block and set different for all product flavor. For example, there are two applications for cab booking, one for driver and one for customer. Both app code is written in one project. So, you need to define two product flavor and set different applicationid.
1 2 3 4 5 6 7 8 9 |
productFlavors { first { versionCode 1 } second { versionCode 2 } } |
Product flavors must belongs to product dimension. It is basically group of product flavors. You must assign all flavors to a flavor dimension; otherwise, you will get the build error : ERROR: All flavors must now belong to a named flavor dimension.
Add following line in builder gradle :
1 |
flavorDimensions "dummy" |
Suppose, you have different Home page of application for guest user and paid user. So, according to product flavour, home page will be called.
Gradle creates every possible combination of build type and product flavor as build variant by default. If you wanna remove any build variant, you can filter it.
1 2 3 4 5 6 7 8 |
variantFilter { variant -> def names = variant.flavors*.name // To check for a certain build type, use variant.buildType.name == "<buildType>" if (names.contains("first")) { // Gradle ignores any variants that satisfy the conditions above. setIgnore(true) } } |
Hope, this blog is helpful for you.
Also, check following link : Android Build
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
Be the first to comment.