Over a million developers have joined DZone.

Beta Testing Your Android App With Build Variants

In this blog post, we are going to learn how to use the build variants feature of Android Studio to create a simple project which is built in two flavors. The build environment will be configured such that each flavor can be built using either a release or debug build type.

· Mobile Zone

Visually compose APIs with easy-to-use tooling. Learn how IBM API Connect provides near-universal access to data and services both on-premises and in the cloud, brought to you in partnership with IBM.

Developers are always excited about releasing their apps quickly without testing it very well and making sure that things work out fine before the final release. As a Developer, you need to ship your app to beta users or testers first and get their feedbacks and improve your app. Software release life cycle are the stages of development you software goes through. Its starts from its initial development to its eventual release.

Stages of a typical software release cycle goes like this: Pre-alpha -> Alpha -> Beta -> Release candidate -> Gold. The main goal of beta testing is to get real-world exposure and to know how your app will feel in the hands of actual users. Google Play Store has a very useful functionality for developers to release their apps in Beta and invite people to test it.

In this blog post, we are going to learn how to use the build variants feature of Android Studio to create a simple project which is built in two flavors (just difference in color background). The build environment will be configured such that each flavor can be built using either a release or debug build type.

What Are Build Variants?

With Build Variants, your app can have multiple versions using the same source code. Though inside the source code, you might want to tweak it to have different functionalities or view for a particular variant to work a particular way. With just one single app, you can have multiple builds types such as debug and release build type. A particular build variant might have a different set of device requirements such minimum API etc. Build variants are the result of Gradle (I wrote an article on Gradle, you can visit it here) using a specific set of rules to combine settings, code, and resources configured in your build types and product flavors.

Why Would You Want to Have Multiple Build Types?

You app might want to use a different API endpoints for debugging and another API endpoints for production or due to limitation on different app stores such as Amazon and Google Play, your app needs to work differently for example Google Play Services is not available on the Amazon app store but it is on the Google Play store, so this becomes very handy in removing the service completely on the Amazon app store and leaving it on the Google Play store. Built variants help you to create different composable pieces of your application in the Android build system. These build types are combined with flavors if you want to, in which you might want to change the look and feel of the app like the background colors, layouts, etc. Another useful usage is if you want different functionalities for your app that has a free and paid version.

We are going to build a simple Lagos Zombie Apocalypse app that uses build types and build flavors using Android Studio.


  1. Create a new project in Android Studio, name LagosApocalypse, enter the usual company domain and all.
  2. Select Empty activity and click on the Next button.
  3. Leave activity name as MainActivity and layout as activity_main and click Finish button.
  4. Open the strings.xml file and add some extra strings
        <string name="app_name">LagosApocalypse</string>
        <string name="button_send">SEND ZOMBIES!</string>
        <string name="town">The town name</string>
        <string name="really_send_zombies">YES</string>
  5. Create a button.xml file inside res/drawable folder. It will draw a rectangle orange button.
    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
  6. Create a background.xml inside the res/drawable folderit will display a gradient blue background.
    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
                    android:type="linear" />
  7. Modify the activity_main.xml so that it looks like this:
    <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_height="wrap_content" />
            android:text="Send Zombies"
            android:layout_height="200dp" />
  8. Add an on click listener on the MainActivity class and implement the onClick method.
    package com.kolocoder.lagosapocalypse;
    import android.os.Bundle;
    import android.support.v7.app.AppCompatActivity;
    import android.view.View;
    import android.widget.EditText;
    import android.widget.Toast;
    public class MainActivity extends AppCompatActivity implements View.OnClickListener {
        protected void onCreate(Bundle savedInstanceState) {
        public void onClick(View view) {
            String town = ((EditText)findViewById(R.id.et_city_name)).getText().toString();
            if (getString(R.string.really_send_zombies).equals("YES")){
                Toast.makeText(this, String.format(
                        "TEST send Zombies to %s", town),
            else {
                Toast.makeText(this, String.format(
                        "Send Zombies to %s", town), Toast.LENGTH_SHORT).show();
  9. Select the app folder, Then, click the Build menu and select the Edit flavors.
  10. The list only contains a defaultConfig. Click on the + button to add a new flavor. Name it blueFlavor and give it the same values as min SDK version and target SDK version as is the case with defaultConfig.
  11. For the application id field, use the package name + the extension .blue.
  12. Enter the version code and version name for this flavor and click on the OK button.
  13. Repeat step 10 to 12 for another flavor. Name that flavor greenFlavor.
  14. Now your build.gradle file should be like this:
  15. Go to the Project panel, select the src folder under the app folder. Create a new folder and name it blueFlavor. Add a new res folder and within that folder, create another one called drawable. Note that you can maintain the same structure as main folder.
  16. Also, do the same for the greenFlavor build’s flavor. The project structure will be like this:
  17. Copy the background.xml and button.xml files from the /main/res/drawable folder and paste them in the blueFlavor/res/drawable folder.
  18. Repeat this for greenFlavor and open the background.xml file in the greenFlavor/res/drawable folder. Modify its content. We will be using a gradient green color for the background.
    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
                    android:type="linear" />
  19. Inside the same folder, open the button.xml file and make the drawable appear in green as well.
    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
  20. Create a new folder and call it debug in the app/src folder.
  21. Inside the debug folder, create a res folder and within the folder, create a values folder.
  22. Copy strings.xml file from the main/res/values folder and paste it inside debug/res/values folder.
  23. Open the strings.xml file and modify the really_send_zombies string resource value to NO.
  24. Now open the  Build Variants panel by going to  Build->Select Build Variant.build-variant
  25. Let's choose the greenFlavorDebug build variant and run the app.
  26. Also select the blueFlavorDebug and run the app again.

References and Further Reading


The Mobile Zone is brought to you in partnership with Strongloop and IBM.  Visually compose APIs with easy-to-use tooling. Learn how IBM API Connect provides near-universal access to data and services both on-premises and in the cloud.

android,android development,gradle,beta testing,mobile

Published at DZone with permission of Chike Mgbemena. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}