Why variant icons matter and how to ship them
When the debug, staging and release builds of an app use the same icon, they look the same on the home screen. A label on the icon tells them apart. This tool adds the label and exports the icon files.
The usual setup is to put a different launcher icon in each build type's source set.
The debug build gets a DEV icon, the staging build gets a
STAGING icon, and the release build keeps the normal icon.
Android density buckets
Android groups screens into density buckets. You provide one bitmap per bucket, and the
system picks the one that matches the screen. Launcher icons go in
mipmap-* directories. All mipmap directories stay in the APK,
even in density-specific APKs, so a launcher can pick a higher-resolution icon. The
buckets follow a 3:4:6:8:12:16 ratio. For a 48×48 px baseline icon:
mdpi: about 160 dpi (1×), 48×48 px.hdpi: about 240 dpi (1.5×), 72×72 px.xhdpi: about 320 dpi (2×), 96×96 px.xxhdpi: about 480 dpi (3×), 144×144 px.xxxhdpi: about 640 dpi (4×), 192×192 px.
The "Android density bundle" download contains
mipmap-<density>/ic_launcher.png for these five buckets. Unzip it
into app/src/<source set>/res/, for example
app/src/debug/res/.
How to wire it into your Gradle build
In app/build.gradle (Groovy), define your build types. initWith
copies the settings of another build type:
android {
buildTypes {
debug { applicationIdSuffix ".debug" }
release { /* prod */ }
staging {
initWith debug
applicationIdSuffix ".staging"
}
}
}
Then create a source set folder for each build type and put its badged bundle inside:
app/src/debug/res/
mipmap-mdpi/ic_launcher.png ← from this tool's bundle
mipmap-hdpi/ic_launcher.png
mipmap-xhdpi/ic_launcher.png
mipmap-xxhdpi/ic_launcher.png
mipmap-xxxhdpi/ic_launcher.png
app/src/staging/res/
mipmap-mdpi/ic_launcher.png ← different bundle
...
Resources in app/src/main/res/ go into every variant. When a resource with
the same name exists in more than one source set, Gradle uses this priority, highest
first: build variant (for example src/demoDebug/), build type
(src/debug/), product flavor (src/demo/), then
src/main/. The debug icon replaces the main icon in debug
builds only.
applicationIdSuffix gives each build type its own application ID. Two apps
with different IDs can be installed on the same device, so debug, staging and release
can sit side by side, each with its own icon.
Keep the badged icons only in app/src/debug/res/ and
app/src/staging/res/. The release build then uses the icon in
app/src/main/res/, which has no badge.
Adaptive icons
Android 8.0 (API 26) added adaptive icons. An adaptive icon has a foreground and a
background layer, defined in res/mipmap-anydpi-v26/ic_launcher.xml with the
<adaptive-icon> element. Each device OEM provides a mask, and the
system uses it to draw all adaptive icons in the same shape, such as a circle or a
squircle.
This tool badges the square ic_launcher.png. The anydpi
qualifier matches all densities and takes precedence over other density qualifiers.
So if your app has mipmap-anydpi-v26/ic_launcher.xml, devices on API 26
and higher use the adaptive icon, and the badged PNG only shows on API 25 and lower.
To badge the adaptive icon, put a badged foreground layer in the variant source set,
under the same resource name as the foreground in main. The layer sizes:
each layer is 108×108 dp, the mask shows the central 72×72 dp, and the safe
zone is the central 66×66 dp. The safe zone is never clipped by the mask. A badge
in the outer 18 dp of the foreground can be cut off.
Themed icons
From Android 13 (API 33), users can turn on themed app icons. A launcher that supports
this tints the <monochrome> layer of the adaptive icon with colors
from the wallpaper and theme. Before Android 16 QPR 2, an app without a monochrome
layer shows its normal icon instead. From Android 16 QPR 2, Android themes icons
automatically for apps that don't provide a monochrome layer. When the launcher
draws a themed icon from your monochrome layer, the badge shows only if that layer
has it too.
Round icons
The manifest attribute android:roundIcon was added in API 25. Launchers
that show circular icons use it and apply a circular mask to it. If your manifest sets
android:roundIcon="@mipmap/ic_launcher_round", badge that icon as well and
put it in the same variant source set. This tool exports the bundle as
ic_launcher.png, so rename the files to ic_launcher_round.png
for that set.