• No products in the cart.

HOW TO CREATE DIFFERENT BUILD VARIANTS IN ANDROID?

HOW TO CREATE DIFFERENT BUILD VARIANTS IN ANDROID?

 

During the development and release phase of developing an android application, you need various types of APK’s or, different versions of APK’s. For instance, during this phase, you might need one debug APK or one debug APK without or with proguard, or an APK for all your free users or even one for all your paid members.

 

Now, the question that arises in our minds is, ‘How do I develop so many different variants of an APK?’, ‘Will having one project for all these different APK’s be enough or do you need to have multiple projects?’ the code is going to be almost the same for all these variants, you will just have to make a few moderations to the API’s or the Application Programming Interface.

 

Now, you must be wondering, how it would be possible for you to achieve this. This can be achieved very easily by using build variants.

 

The main focus of this blog post is to explain to you the concept of build variant as well as to brief you on how you can achieve the task of creating different build variants of android.

 

So, buckle up your seatbelts and let’s get started!!

 

BUILD TYPES AND BUILD VARIANTS:

 

Several build types like: ‘debug’ and ‘android’ are created while the development of an android app. While doing that we can also focus on the different flavors for the app like: the free flavor and the paid flavor. Those users who use the application for free will be directed to the free flavor of the app meanwhile, all the paid users will be directed to the paid flavor of the app.

 

The only thing you need to do is add the different build types in your mobile app.

 

If you don’t end up choosing any build type then, the default build type would be: debug and release.

 

You will be able to spot the build variant option on the left part of your screen. If you are not able to find the build variant option then find the resource manager option. Build variant option will be just below that in android studio.

 

Build -> Select the Build Variant option or you can just press cmd + shift + caps lock A and search for “Build Variant”:

 

Android Build Types and Product Flavors - JournalDev

 

So, this is how you change a build type. All that you need to do is select the build type from your build variant and sync the project.

 

But now, the question that comes to our mind is: “how to create a build type?”

 

ADD BUILD TYPES:

 

Creating Different Build Variants in Android

 

In this part of the blog we will be having a look over the process of adding build types in case of androids.

 

The default build types that are created when you create any project are: debug and release. But, if you want any other build types than the default ones then you will have to manually add then to your module: built.gradle file and under the block named buildTypes.

 

An example of the same has been under-mentioned:-

 

android {

 

defaultConfig {

applicationId “com.mindorks”

versionCode 3

versionName “0.0.3”

}

 

buildTypes {

debug {

versionNameSuffix “.dev”

debuggable true

}

release {

debuggable false

minifyEnabled true

shrinkResources true

proguardFiles getDefaultProguardFile(‘proguard-android.txt’), ‘proguard-rules.pro’

}

minifiedDebug {

versionNameSuffix “.dev”

debuggable true

minifyEnabled true

shrinkResources true

proguardFiles getDefaultProguardFile(‘proguard-android.txt’), ‘proguard-rules.pro’

}

}

}

 

In the above code it is lucidly visible that along with the two default build types a third new one is also present namely: minifiedDebug. minifiedDebug is a build type which is a concoction of the debug and proguard build types.

 

In a similar mannar you can create a build type namely: noMiniFedRelease. This build type will be a combination of release and without proguard.

 

Initwith is a function which you can use in case you want to use some of the properties of the old build types you have created while also modifying it by adding some new properties. This will help you save time as you won’t have to create every build type right from scratch.

 

The syntax of using InItWith is:

 

newBuildType {    initWith debug    versionNameSuffix “.newbuild”    …}

 

ADDING PRODUCT FLAVORS:

 

Product Flavors in Android. Let's imagine you have an Awesome… | by Victor  Apoyan | Medium

 

Product flavors are just different variants of your app. For instance, you can think of adding product flavors like ‘development’ and ‘production’ in your app. These flavors could have different API features whereas maintaining the same working flow.

 

For adding these flavors the block used is: productFlavor. Each product flavor in your code must have a particular dimension:

 

android {    …    defaultConfig {…}    buildTypes {        debug{…}        release{…}    }        flavorDimensions “version”    productFlavors {        development {            dimension “version”            versionNameSuffix “.dev”        }        production {            dimension “version”            versionNameSuffix “.prod”        }    }}

 

The best thing about product flavors, I believe, is the fact that each product flavor is associated with the build type. For instance, if your code has two build types namely: ‘debug and release’ then the build variants will be:

 

  • DevelopmentDebug
  • developmentRelease
  • ProductionDebug
  • ProductionRelease

 

This is how you can create a product flavor and use it in creating different versions of your build type.

 

I hope that I was able to explain to you the concept of build types and the procedure you need to follow in order to create your own build type.

 

So, that is it for this blog!

 

Thank you for reading so far. I hope you have a wonderful rest of your day!!! 🙂

 

 

June 26, 2021

0 responses on "HOW TO CREATE DIFFERENT BUILD VARIANTS IN ANDROID?"

Leave a Message

top

Copyright © 2020 NullClass