Nautilus - Thumbnailer for APK files



On Android devices, all programs are installed thru some APK archives. Under Gnome Nautilus, these APK archives are recognised as a specific mime types and are displayed with some generic text file icon.

As most of the time the name of these APK archives is not very friendly, it is difficult to associate an APK file with the Android application it contains. To help you with this association, it could be very helpful to display the application icon as it is done under Android instead of the generic icon.

Thanksfully, under Gnome Shell, Nautilus allows to generate a specific thumbnail according to the APK mime type application/ As APK archive are supposed to contain their Android application icon, it becomes possible to display the application icon as the Nautilus thumbnail. You can also add APK version provided by the embedded manifest.xml.


This article explains all the steps needed to configure Nautilus to display the APK embedded application icon as thumbnail. This allows you to handle your APK files from Nautilus as they appear on your Android device.

This procedure has been tested under Ubuntu and Ubuntu Gnome 16.04 LTS and even LUbuntu with PCManFM.
It should be applicable to many other distributions.

1. Install packages

We will use aapt tool, from Android SDK to extract data from APK files. Either you have already installed the complete SDK or you just need this tool from Ubuntu repository.

So, for the thumnailer to do its job, we need to install the following packages : gvfs-copy, unzip, aapt and netpbm tools.

# sudo apt-get install gvfs-bin aapt unzip netpbm

2. Create the Thumbnailer

When Nautilus needs to generate a thumbnail for a file, it is calling a 'thumbnailer'. This program (or script) is in charge of generating the thumbnail in a PNG format with a given height.

When we deal with APK archives, the thumbnail can be generated from the embedded icons. In fact every APK archive is a standard ZIP archive and is most of the time embedding some icons that will be used to display the application icon on the android desktop.

Icons may be available in different formats in the package (ldpi, mdpi, hdpi, xhdpi), but most of the time official package icon is having a mdpi or hdpi resolution.

You can use the aapt tool available from android SDK to determine the application icon. Icon files are listed with the d badging option.

# aapt d badging com.whatsapp.apk | grep application | grep icon
application: label='WhatsApp' icon='res/drawable-hdpi/icon.png'

The following script is a Nautilus 'thumbnailer' that will do the thumbnailing job using aapt :

#!/usr/bin/env bash
# ---------------------------------------------------
# Thumbnailer for APK archives files
# Display embedded icon and version number (option)
# Procedure :
# Depends on :
#   * unzip
#   * aapt
#   * pngtopnm, pnmtopng, pnmcrop, pnmpad, pnmscalefixed and pnmcomp (netpbm package)
# Parameters :
#   $1 - path of APK archive
#   $2 - path of generated thumbnail
#   $3 - height of thumbnail in pixels
# Revision history :
#   04/08/2013, V1.0 - Creation by N. Bernaerts
#   11/08/2013, V1.1 - Use aapt to get icon file
#   05/11/2014, V2.0 - Add version display
#   06/11/2014, V2.1 - Don't use renamed aapt anymore
#   15/11/2014, V3.0 - Use URI to handle network shares
#   07/10/2017, V3.1 - Speedup with netpbm tools
#   15/12/2018, V3.2 - Rework for bubblewrap compatibility
# ---------------------------------------------------

# check tools availability
command -v aapt >/dev/null 2>&1 || { echo "[error] aapt missing"; exit 1; }
command -v unzip >/dev/null 2>&1 || { echo "[error] unzip missing"; exit 1; }
command -v pbmtextps >/dev/null 2>&1 || { echo "[error] pbmtextps missing"; exit 1; }
command -v pnmcrop >/dev/null 2>&1 || { echo "[error] pnmcrop missing"; exit 1; }
command -v pnmpad >/dev/null 2>&1 || { echo "[error] pnmpad missing"; exit 1; }
command -v pngtopnm >/dev/null 2>&1 || { echo "[error] pngtopnm missing"; exit 1; }
command -v pnmscalefixed >/dev/null 2>&1 || { echo "[error] pnmscalefixed missing"; exit 1; }
command -v pnmcomp >/dev/null 2>&1 || { echo "[error] pnmcomp missing"; exit 1; }
command -v pnmtopng >/dev/null 2>&1 || { echo "[error] pnmtopng missing"; exit 1; }

# check params
[ "$3" = "" ] && { echo "[error] 3 params are needed : file file-thumb thumb-size"; exit 1; }

# set to no to remove version number on the icon

# get parameters

# generate temporary local filename
TMP_PNM=$(mktemp -t "thumb-apk-XXXXXXXX.pnm")

# get application icon
ICON=$(aapt d badging "${FILE_LOCAL}" | grep "application-icon" | sed 's/^.*icon-\(.*\):.\(.*\).$/\2/' | tail -1)

# if icon exists, extract icon & generate thumbnail 
if [ "$ICON" != "" ]
    # if needed, add version display options
    if [ "$DISPLAY_VERSION" = "yes" ]
        # get version
        VERSION=$(aapt d badging "${FILE_LOCAL}" | grep "versionName=" | sed 's/^.*versionName=.\([0-9.]*\).*$/\1/')

        # calculate optimum font size
        FONT_SIZE=$((${SIZE} / 10 + 1))

        # generate version image
        pbmtextps -fontsize ${FONT_SIZE} "${VERSION}" | pnmcrop - | pnmpad -white -left 4 -right 4 -top 4 -bottom 4 - | pnmpad -black -left 2 -right 2 -top 2 -bottom 2 - > "${TMP_PNM}"

        # generate icon including version number
        unzip -p "${FILE_LOCAL}" "${ICON}" | pngtopnm - | pnmscalefixed -xysize ${SIZE} ${SIZE} - | pnmcomp -align center -valign bottom "${TMP_PNM}" - | pnmtopng > "${FILE_THUMB}"

    # else, no version needed
        # generate plain icon without version number
        unzip -p "${FILE_LOCAL}" "${ICON}" | pngtopnm - | pnmscalefixed -xysize ${SIZE} ${SIZE} - | pnmtopng -downscale -compression 0 - > "${FILE_THUMB}"

# remove temporary local file
rm -f "${TMP_PNM}"

You can install this thumbnailer with the following commands :

# sudo wget -O /usr/local/sbin/apk-thumbnailer
# sudo chmod +rx /usr/local/sbin/apk-thumbnailer

If you want the thumbnailer to display version number on the icon, you need to edit the script and set DISPLAY_VERSION="yes"

3. Declare the Thumbnailer

To allow Nautilus to use the proper thumbnailer for APK archives, you need to declare the previous script as the thumbnailer for the mime type of APK archives (application/

This declaration is done via a apk.thumbnailer file placed under /usr/share/thumbnailers. This file follows a specific format, where association between the mime type and the thumbnailer is done.

A complete description of this file format is available from Gnome Developers site on the page Installing a Thumbnailer Program.

As we want to get APK icon even for file which are accessed thru a network share, we will use the file URI instead of it's plain filename. This will allow the thumbnailer script to handle the files thru GVFS.

[Thumbnailer Entry]
Exec=/bin/bash /usr/local/sbin/apk-thumbnailer %i %o %s

You can download this thumbnailer declaration file with the following commands :

# sudo wget -O /usr/share/thumbnailers/apk.thumbnailer

4. Bubblewrap patch

Under latest gnome version, all thumbnails are generated using bubblewrap sandboxing. But under Ubuntu 18.04, there is a bug in default gnome bwrap parameters, and thumbnails are not generated.

So to solve the problem, you need to declare a local bwrap proxy script which will modifiy the erroneous parameters and call original bwrap. This bwrap proxy script is available from my GitHub repository.

#!/usr/bin/env bash
# bwrap wrapper to correct nautilus 3.26.4+ bug for external thumbnailers under debian based distros
#  * add --ro-bind needed by imagemagick tools
#  * replaces --symlink calls with equivalent --ro-bind calls

# intialise parameters array

# since editing /usr/local/bin requires root privilege, we can trust it
[ -d "/usr/local/bin" ] && ARR_PARAM=( "${ARR_PARAM[@]}" "--ro-bind" "/usr/local/bin" "/usr/local/bin" )

# add both --ro-bind needed by thumbnailers using imagemagick tools
[ -d "/etc/alternatives" ] && ARR_PARAM=( "${ARR_PARAM[@]}" "--ro-bind" "/etc/alternatives" "/etc/alternatives" )
[ -d "/etc/ImageMagick-6" ] && ARR_PARAM=( "${ARR_PARAM[@]}" "--ro-bind" "/etc/ImageMagick-6" "/etc/ImageMagick-6" )
[ -d "/var/cache/fontconfig" ] && ARR_PARAM=( "${ARR_PARAM[@]}" "--ro-bind" "/var/cache/fontconfig" "/var/cache/fontconfig" )

# if exists, enable $TMPDIR
[ -n "${TMPDIR}" ] && [ -d "${TMPDIR}" ] && ARR_PARAM=( "${ARR_PARAM[@]}" "--bind" "${TMPDIR}" "${TMPDIR}" )

# loop thru original parameters
while test $# -gt 0
    case "$1" in
        # --symlink : convert to --ro-bind
        "--symlink") shift; shift; ARR_PARAM=( "${ARR_PARAM[@]}" "--ro-bind" "$1" "$1" ); shift; ;;
        # others : add parameter
        *) ARR_PARAM=( "${ARR_PARAM[@]}" "$1" ); shift; ;;

# call original bwrap
/usr/bin/bwrap "${ARR_PARAM[@]}"

You can install it with these simple commands :

# sudo wget -O /usr/local/bin/bwrap
sudo chmod +rx /usr/local/bin/bwrap

5. Enjoy your APK Thumbnails

You can now purge your thumbnails to allow them to re-generate and restart nautilus to reload the thumbnailer scripts.

# rm -r $HOME/.cache/thumbnails
# nautilus -q

Please note that if you run Lubuntu, thumbnails should be removed under $HOME/.thumbnails and thumbnailer will work after next reboot.

You will now enjoy to see your APK archives displayed with their embedded icons.

Hope it helps,

Signature Technoblog

This article is published "as is", without any warranty that it will work for your specific need.
If you think this article needs some complement, or simply if you think it saved you lots of time & trouble,
just let me know at This email address is being protected from spambots. You need JavaScript enabled to view it.. Cheers !

icon linux icon debian icon apache icon mysql icon php icon piwik icon googleplus