How to make Build Variants in Android Studio?

We may need to create different versions of an APK file based on an application type (free or paid application), the server environment type (QA, UAT)  & etc.

To reduce the convolution of making different versions of an APK file, Android Studio uses Gradle, a build toolkit, to automate and manage the build process. It allows us to define flexible custom build configurations. Each build configuration can define its own set of code and resources while reusing parts common to all the application versions. It enables us to have multiple similar versions of an app within a single code base like different colors, dependencies & etc.

Step 1: Create a New Project with Android Studio.

Name the Application to {anything of your choice} & then click Next. I have currently named it buildvariant.

Step 2:  Configure your app

Select the API Version (I took it as 15) as per your Target Audience. Under Phone and Tablet select the API and the click Next.

Select Empty Activity and then click Next.

Keep the Activity name as MainActivity (or any name of your choice) and click Finish.

MainActivity is the Default name

Step 3:  Project Settings

Under the heading Gradle Scripts browse for build.gradle(Module:app)

Append the build.gradle file with the following under the buildTypes DSL:

         <your existing code/configurations>
        qa {
            initWith debug
            jniDebuggable true
            applicationIdSuffix ".qa" //uniquely identify the app qa
            manifestPlaceholders = [buildtestAppName: "buildtest qa"] //used to change the name of the app according to the build variant

        uat {
           initWith debug
           jniDebuggable true
           applicationIdSuffix ".uat" //uniquely identify the app uat
           manifestPlaceholders = [buildtestAppName: "buildtest uat"] //used to change the name of the app according to the build variant

You can take build variant names as per your choice. (I have made assumptions of taking the build variants as qa and uat.)

Step 4:  Sync Gradle

After the Sync is complete from the buildvariants tab, select the Variant you have to work on.

Under the Manifests file select the AndroidManifest.xml file and change the android:label to


Step 5: Directory and Code Setup.

Click on Explorer dropdown and select Project.

  1. Click on app–>src
  2. Right click on src–> New–> Directory
  3. Give name to the Directory and then click on the Named Directory
  4. Right click on the Directory–> New–> Folder–> Res Folder
  5. Under Res Folder–> New–> Image Asset
  6. Select the Image and click Next and then click Finish.


After creating the Res Folder, copy the image and Paste the same into the Res Folder.

Step 6: Using build variants

Under QA folder, create a XML layout and name it splash_layout.

Write the following code under splash_layout.xml:


Note: Similarly recreate Step 6 for UAT with the same name as the one kept in QA.

Step 7: In the main folder add a New Empty Activity and name it SplashActivity.

SplashActivity consists of the following code:

package com.example.jrb.buildtest;
 import android.content.Intent;
 import android.os.Bundle;
 public class SplashActivity extends AppCompatActivity {
 protected void onCreate(Bundle savedInstanceState) {

Step 8. In the AndroidManifest.xml check for the activity and make sure on keeping it attached to the SplashActivity.

Step 9. Hallelujah we are done, now Debug your Application according to the build variant.