jamesob.com
Published in

jamesob.com

Identifying Android Build Types

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.

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Icon Debug</string>
</resources>

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:

<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_bg" />
<foreground android:drawable="@drawable/ic_launcher_fg" />
</adaptive-icon>

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)
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<!--- Place your original vector icon here -->
</item>
<item
android:height="16dp"
android:bottom="16dp"
android:gravity="bottom">
<shape android:shape="rectangle">
<corners android:radius="2dp" />
<size
android:width="10dp"
android:height="10dp" />
<solid android:color="#80FFFFFF" />
</shape>
</item>
<item
android:bottom="16dp"
android:gravity="center_horizontal|bottom">
<!--- Debug Indicator Vector Drawable --->
<vector
android:width="16dp"
android:height="16dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#B3000000"
android:pathData="M8.35,3C9.53,2.83 10.78,4.12 11.14,5.9C11.5,7.67 10.85,9.25 9.67,9.43C8.5,9.61 7.24,8.32 6.87,6.54C6.5,4.77 7.17,3.19 8.35,3M15.5,3C16.69,3.19 17.35,4.77 17,6.54C16.62,8.32 15.37,9.61 14.19,9.43C13,9.25 12.35,7.67 12.72,5.9C13.08,4.12 14.33,2.83 15.5,3M3,7.6C4.14,7.11 5.69,8 6.5,9.55C7.26,11.13 7,12.79 5.87,13.28C4.74,13.77 3.2,12.89 2.41,11.32C1.62,9.75 1.9,8.08 3,7.6M21,7.6C22.1,8.08 22.38,9.75 21.59,11.32C20.8,12.89 19.26,13.77 18.13,13.28C17,12.79 16.74,11.13 17.5,9.55C18.31,8 19.86,7.11 21,7.6M19.33,18.38C19.37,19.32 18.65,20.36 17.79,20.75C16,21.57 13.88,19.87 11.89,19.87C9.9,19.87 7.76,21.64 6,20.75C5,20.26 4.31,18.96 4.44,17.88C4.62,16.39 6.41,15.59 7.47,14.5C8.88,13.09 9.88,10.44 11.89,10.44C13.89,10.44 14.95,13.05 16.3,14.5C17.41,15.72 19.26,16.75 19.33,18.38Z" />
</vector>
</item>
</layer-list>

--

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
James O'Brien

James O'Brien

More from Medium

Android 13: Notification Runtime Permission

Quick Note: Custom WebView Class Won’t Display Virtual Keyboard After Kotlinized

How I reduced my App Size: Android App Bundles

BeeHive View in Android