Generate Amazon Underground Launcher Icons
2 min read

Generate Amazon Underground Launcher Icons

Generate Amazon Underground Launcher Icons

TL;DR: Use (adapt) the script below to automatically generate the Amazon Underground application launcher icons.

I was toying with the idea to build an Amazon Underground version of one of my applications. According to their rules, you need to:

  • Repackage your app
  • Name custom permissions (Lollipop)
  • Apply Amazon Underground branding
  • Migrate API (if necessary)

Initially I looked for a way to automatically generate the launcher images through gradle. However, I could not find any way and I figured it's easier to build a shell script.

Assumptions and results

The script makes following assumptions:

  • You have bash
  • You have ImageMagick installed
  • The script is located at the root of the project
  • Your project's main module (where launcher icons are located) is named app (like the default android project created by Android Studio)
  • Your launcher icons are named ic*launcher.png and are located in your main module's mipmap resources (\_app/src/main/res/mipmap-...*)
  • You have internet access
  • The Amazon Underground flavour is named amazonUnderground

To be more clear, here's the reference layout:


Running the script will produce following results:

  • It will create the appropriate folder
  • It will produce a set of launcher icons complying with Amazon's requirements


The script has three main parts:

  1. Download resources from Amazon (the overlay images)
  2. Build the necessary structure
  3. Generate the overlay images

A temporary directory is created for file operations (download, unzip).

The full script

Initially, I wanted to avoid loops, but it's slightly more elegant with. The script is:


# Some variables
ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
TEMP_DIR=`mktemp -d -t amazon`

# Check if the temp directory was created successfully
trap "{ cd - ; rm -rf $TEMP_DIR; exit 255; }" SIGINT

echo "Temp dir: [$TEMP_DIR]"

# Download and unzip the sash from Amazon
echo "Download resources"
curl -s -O
unzip -qq

# Create the mipmap directories (if not present)
echo "Prepare folders"
for i in xxxh xxh xh h m; do
    mkdir -p "$UNDERGROUND_DIR/res/mipmap-${i}dpi"

# Build the overlapped images
echo "Build launcher icons"

for i in xxxh,192 xxh,144 xh,96 h,72 m,48; do
    dpi=$(echo $i | cut -d',' -f 1)
    resolution=$(echo $i | cut -d',' -f 2)
    echo "...${dpi}dpi"
    composite -compose src-over \
        "${SASH_PATH}-${resolution}.png" \
        "$BASE_DIR/res/mipmap-${dpi}dpi/ic_launcher.png" \

# Restore the previous directory (clean script)
# and remove the temp
cd -
rm -rf $TEMP_DIR
echo "Done"
exit 0

Now, I only have a Mac to test the script on. It should work out of the box on any unix/linux properly configured. You'd need something like cygwin to make this work on windows (aka overkill). I'd love if anyone could contribute a .bat file.


It would be useful if one could leverage gradle somehow (a separate task, plugin maybe). This way, we could e.g. cache some things, remove some dependencies...

Possible extensions of the script could be adding the generated files to e.g. git and committing the changes or caching the downloaded file somewhere locally.