Identifying Android Build Types

James O'Brien
Mar 4 · 3 min read

During development it’s common to add different build variants. Build variants are used to create different versions of your application within a single project. This can be used to differentiate between a paid version and a free version of an applications, or white-label a solution for multiple identities.

In this post, I’m going to briefly show how to add your own build types and provide two methods for differentiating for quick development and testing.

Adding Build types

Adding build types is relatively simple. Opening your application’s build.gradle file, you should see that Android Studio has already created a buildType for a release. We can add our own buildTypes here for debug and enable debugging.

Overriding Resources

At run time, Android figures out the best resources to use based on your configuration. You have the ability to define items for different orientations, OS version number, and even things like screen size by creating items with the same name but a different qualifier.

https://developer.android.com/guide/topics/resources/providing-resources

Overriding the Label

To override the application name for debug versions we need to create a new strings file in the debug source set.

In the ‘New Resource File’ screen, we can create a new version of the strings.xml file and select the debug source set. We then add a new string for app_name with our custom label.

Below is how the file would look. There is a single string definition, with the same name as the one in the main strings file, however it has a name specific to the build type.

Using Custom Launcher Icons

The adaptive icon builder creates a layout with two layers: a background and a foreground. Here’s an example of what your adaptive launcher icon may look like:

Using the method in the previous section for overriding resources, we can create a new foreground drawable in the debug specific values folder. This way we can add overlays to our launcher to differentiate the build variant.

We can then change the foreground icon to have extra layers using a LayerListDrawable. We want to add it as the first item so it appears behind all other items.

Icon Banner with Paw Print (Dog Fooding)

jamesob.com

Writings from James O’Brien

James O'Brien

Written by

Englishman attempting the American dream as an android developer at The Meet Group.

jamesob.com

Writings from James O’Brien

More From Medium

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade