Install different versions of same app on same device- Android

Kiran Choudhary
3 min readFeb 4, 2022

Product Flavor Android

Build variants/product flavors are nothing but different versions of your app that you may release to the different user-base. But where to use it?
It may be the case that you are using different back-office URLs, separate app icons and other stuffs for all your builds and you have to maintain separate projects or maybe commenting stuff and release to all your users. What if we can achieve all of this and more in just single code/project and still be able to deliver multiple builds. We can achieve this by using the build variant in android and its product flavors.

Before I start jabbering all about product flavor and how I use it, I must tell you, this post is fairly simple and can be read and referred by developers of any level but, if you have a bit of knowledge about Build settings and Schemes, trust me you are gonna kill it.

Background

Could you please make 3 copies of our app, pointing to different servers. I will need it in tomorrow’s presentation.

Project Manager

uhhh! copies?

Seriously! what are we up to?

Since you now know the background motivation of ‘product flavour’ for me, Let’s discuss what are we going to achieve.

  • Single code + 3 builds.
  • Make decisions based on app installed.
  • Distinguishing between the apps.

Basic Idea!

It’s very simple, only 2-step process.

Step 1: Define the flavors:

Defining the flavors is a very easy task, that we do in app level build.gradle.

android {
compileSdkVersion 26
buildToolsVersion '26.0.0'

defaultConfig {---}
buildTypes {---}
productFlavors {
qa {
applicationIdSuffix ".qa"
versionCode 1
versionName "1.0"
}
demo {
applicationIdSuffix ".demo"
versionCode 1
versionName "1.0"
}
dev {
applicationIdSuffix ".dev"
versionCode 1
versionName "1.0"
}
uat {
applicationIdSuffix ".uat"
versionCode 1
versionName "1.0"
}
}
}

Build your projects after this.

Step 2: Generating a specific build

After building the project, you can select a build variant from all the option that we added as flavors in the build.gradle and when you run/generate an apk, tha apk is generated for that particular flavor.

The build variant can be selected at the bottom left:

Once you click on build-variants, you will get another window with a drop-down to select a variant:

Now select a variant and generate a build.

So suppose now I want a build on QA environment. I make the changes in app APIs definition, select the QA option from build variant and install a build.
Again, I will change the API definitions to PROD, select the Prod option from build variants and install a build.

And done! Now you have two builds of your app installed on your device. One pointing to QA and other pointing to UAT.

--

--