Having different variants (debug/staging/release) of your app on a single device

Chizoba Ogbonna
Chizoba’s Blog
Published in
2 min readFeb 3, 2019
Photo credit: Atlassian

Building applications for scale requires one to have different environments for testing and debugging, up onto the production stage. This is also the case in Android, but because of the mechanism Android uses to depict unique applications on a device (i.e. package name/applicationId), your debug/staging/release build variants cannot co-exist, and will always be replaced when another variant is installed.

How can we solve this?

As part of the Android Gradle Plugin, there is a property, applicationIdSuffix, that can be added to your build types to create a change in your applicationId. See sample below:

What happens is that the applicationId of each build variant becomes the following:

  1. release variant - com.github.chizoba (uses the default applicationId)
  2. staging variant - com.github.chizoba.staging
  3. debug variant - com.github.chizoba.debug

Hence, this does not create any conflict amongst build variants on your android device, and they can exist as three different variants/types of the same application.

Awesome yeah?

Credit: Giphy

But then, you would realise that all application variants will have the same name. How then do you know which is the debug/staging/release version? 🤷‍♂️😯

Well… The Android Gradle Plugin also provides us with another property, manifestPlaceholders, that allows us insert variables, defined in your build.gradle file, into your AndroidManifest.xml. See sample below:

By setting your application name (using android:label) to a wild card, and setting that wild card’s value in each variant, you automatically change the application name depending on which variant you run. Based on each variant in the example above, your application’s name will be the following:

  1. release variant - AppName
  2. staging variant - AppNameStaging
  3. debug variant - AppNameDebug

I hope you enjoyed learning this interesting concept 💯💯💯.

Don’t be selfish 😋, please share this with others 😊.

And make use of the awesome “clap” feature to show how much you learnt 👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏 😁😁😁😁.

Stay tuned for more interesting tips like this 💃🏾 🕺🏾🙂✌🏼.

--

--