Installing debug and release build variants at the same time — Android.

Adalberto Plaza
Degoo
Published in
3 min readApr 21, 2021
Header

Having different environments to work with when developing applications or system is a good (and necessary) practise. Those environments are usually Debug and Release in Android (Develop and Production)

If you, as a developer, want to keep a long-term tracking of the app you are working on, it’s a very good idea to keep it installed as a “real user”. This is, not clearing or uninstalling/installing it over and over again to “test” development changes. But use to happen that lot of Android developers use the same device (among others) as personal but also as development one. Hence the same app can not be installed twice just depending on the environment.

Therefore you will find issues having both build variants if you don’t prepare them for that. This happens, because by default, both will have the same package name but different signatures. Or you will be simply overriding them all the time if you make them identical (not a good idea either).

Customizing the build variants

A very simple solution is to make the variants just a bit different between them. Allowing to the Android system to install both at the same time, in the same device. How this can be achieved?

As we said, both variants have the same package name or ID, but different signatures. And this is a problem for the Android system, because the way it manages the apps is by identifying them by the package name and “checking the singularity” by their signature. So, the first approach is just to add a suffix in the debug variant to differentiate it from release. And we will do it via Gradle. That way, Android will know that both variants are actually different apps.

Easy! Now you will have “two apps” with different package names.

Release -> com.myapp.android
Debug -> com.myapp.android.dev

We have solved the main problem. But there are a couple of small issues yet. You can now install both build variants in your device at the same time, but both of them have the same name and the same icon. So it could be a bit confusing, couldn’t it? Let’s fix it!

Customizing variant name

As you probably know, you can specify different resources for each variant or each flavour you have in your project. So the solution to change the name is pretty straight forward to do in this case.

In your main Manifest.xml, you are probably specifying your app name referencing a string resource as follows:

That string resource is probably inside your strings.xml main file as well. But there’s a very useful option to specify different resources depending on the build or flavour variant. In this case, we introduced a change for debug variant (suffix), right? Let’s specify a different app name for it as well.

To proceed, just create a new strings.xml (if you don’t already have it) inside the path of your variant:

project_root/src/debug/res/values/strings.xml

And specify the new name for the variant:

Note: you will still have your original strings files with all your app strings:

project_root/src/release/res/values/strings.xml

Et voilà! Now Gradle will select the new name when building the debug variant.

Customizing variant icon

As a final step, we also have the possibility of setting a different icon for each build variant. In the same way the name is defined in the Manifest.xml, the icon is declared there too.

So let’s follow the same strategy than the previous point. It’s as easy as having a different icon per variant folder.

project_root/src/release/res/mipmap/ic_launcher.png

project_root/src/debug/res/mipmap/ic_launcher.png

And here it’s the result how it looks in our day to day in Degoo:

Both build variants installed at the same time

--

--