White Labeling Android Apps: Getting Started

In this tutorial, you’ll learn step by step how to white label your Android apps by using Android flavors and build variants. By Aaqib Hussain.

Leave a rating/review
Download materials
Save for later
Share

In this fast-moving era of technology, everything has a mobile app. Because of this, almost everyone wants to compete in the mobile market by developing an app like those that are already popular. Apps like Uber, Lyft and Free Now are examples of that.

Now, imagine that you’ve developed an app for a client and another client comes to you with the same requirement… what would you do? Would you recreate your codebase for the other client from scratch?

No, that would be a bad idea. It would take a lot of your time to essentially rewrite the app that you’ve basically already written. A more cost-effective approach is white labeling. In this tutorial, you’ll learn how to white label Android apps using Android flavors, or build variants.

Getting Started

You’ll start out with an app called Animaldom, which consists of a grid view of pictures of animals.

Download the project from the top or bottom of this tutorial by clicking the Download Materials button. Fire up Android Studio and open the Starter Project.

After Gradle builds, run the app and you’ll see something like this:

Animaldom app

Now, assume the client wants you to develop the same app, but for cats and call it catsPlanet. What would you do in such a case?

The easiest way to do this would be to use white labeling.

What Is White Labeling?

White labeling is when a company takes a product or service developed by another company and rebrands it as their own. White labeling in Android simply means taking an existing app and rebranding it or customizing it by changing the app’s icon, theme, styles, name, APIs, etc. The way this is usually done is that the developer, or producer, sells the app to the company wanting to brand it as their own, often at a reduced cost than to custom build the entire app.

To white label Android apps, you need to add product flavors to the project.

What Are Product Flavors?

Product flavors let you create multiple variants of an app while still using its existing codebase. A variant doesn’t just mean you can change the color theme or the logo of the app. It also means you can hide or show specific features you want in other variants. To do this, you need to define some rules in the build.gradle, which you’ll learn more about later in this tutorial.

Flavor Dimensions

Flavor dimensions let you create groups of flavors that you can combine with flavors of other dimensions. For example, if you have an app that you want to build twice, each with different API endpoints, then using flavor dimensions would be a good idea. You would have one flavor that uses the first set of API endpoint, and a second flavor for the other endpoints. You can mix and match these flavors with flavors from other flavor dimensions, for example, if you wanted a different build for both animaldom and catsPlanet. See the following code example:

flavorDimensions 'version', 'api'
productFlavors {

  animaldom {
    dimension 'version'
  }

  catsPlanet {
    dimension 'version'
    applicationId "com.raywenderlich.android.catsPlanet"
  }

  development {
    dimension 'api'
    // set up development environment url
    // ...
  }

  production {
    dimension 'api'
    // set up production environment url
    // ...
  }
}

This sets up two different flavor dimensions: version and api. From the example above, you can think of this as api for the differing API endpoints and version for animaldom versus catsPlanet builds. You have two flavors for the version flavor dimension: animaldom and catsPlanet, then two for the api dimension: development and production. These flavors can be combined, along with build types for debug and release, as you’ll see below.

This generates a total of eight build variants. For Animaldom, you have:

  • animaldomDevelopmentDebug
  • animaldomDevelopmentRelease
  • animaldomProductionDebug
  • animaldomProductionRelease

For catsPlanet, you have:

  • catsPlanetDevelopmentDebug
  • catsPlanetDevelopmentRelease
  • catsPlanetProductionDebug
  • catsPlanetProductionRelease

Ever since Gradle plugin 3.0.0, you need to assign a flavor dimension once you define a flavor. If you only define one dimension, all the configurations for the flavors belong to that dimension by default.

What Is a Build Type?

A build type is the configuration for the mode of the project you want to build. The two default build types are debug and release. Like product flavors, build types are also defined in build.gradle, which is also where the certificate signing for release mode APK is. Here’s how you define a build type:

buildTypes {
  release {
    minifyEnabled false
    proguardFiles getDefaultProguardFile(
      'proguard-android-optimize.txt'), 'proguard-rules.pro'
  }
}

Now, it’s time to get started with some code!

Adding Flavors to the App

There are two ways you can add flavors to your app:

  1. From the project structure.
  2. From build.gradle.

Adding Flavors From the Project Structure

Click File ▸ Project Structure then click on Build Variants on the left-hand side of the dialog that appears.

Selecting build variants

Then click on the + button under the Flavor tab and select Add Dimension.

Adding dimensions

Type version and click OK. This will add the flavor dimension version to the list of dimensions. After that, click the + button again and select Add Product Flavor.

Adding a product flavor

Type in animaldom and click OK. You’ll see the following view:

Separating Animaldom from the main app

You can keep all of the defaults for this. Click OK to add animaldom to your project.

Now, go back to Project Structure and add a new product flavor. Name it catsPlanet.

Adding catsPlanet

For the Application ID add com.raywenderlich.android.catsPlanet and click OK.

After Gradle syncs, you’ll see four build variants in the Build Variants tab on the left.

Variants in the Build Variants tab

If that tab isn’t visible, enable it by navigating to View ▸ Tool Windows ▸ Build Variants.

Enabling build variants

Adding Flavors From build.gradle

Note: If you followed along in the previous section, you don’t need to add any code here since it was automatically added in the previous step. However, it’s recommended you continue reading so you understand the generated code.

Open the app’s build.gradle file and add the following code inside the android tag, after the buildTypes tag:

//1
flavorDimensions 'version'
productFlavors {
  //2
  animaldom {
    dimension 'version'
  }
  //3
  catsPlanet {
    dimension 'version'
    applicationId "com.raywenderlich.android.catsPlanet"
  }
}

Here’s what each part of this code does:

  1. Here, you define the necessary flavor dimension. To keep it simple, you just name it version because you are only developing a different version of the same app.
  2. You create this flavor to keep the original version, Animaldom, intact as a separate flavor.
  3. The new flavor, catsPlanet, needs to be a different app. Therefore, it needs a different app ID. You don’t have to specify the dimension you only have one dimension in your project.

Your next step will be to set up separate directories for each of your apps.