Improve Android APK installation time on Pepper

How to reduce Android APK size to optimize deployment on Pepper QiSDK robot
Improve Android APK installation time on Pepper

As a developer, you may want to accelerate the build and the deployment of an application on Pepper from Android Studio. Here is a useful optimization trick to optimize the build and deploy time, to reduce the size of the application package (APK) and therefore improve installation and deployment time.

Prerequisites

Reducing installation time

Installation time of an application on Pepper from Android Studio depends on the size of the application package (APK), the limitations of ADB and your wifi bandwidth.

Here is the recommended trick to use in all your applications to reduce the package size and therefore improve the installation time.

Create multiple APKs

When building a project, a single APK is generated by default. This APK supports all the target devices whenever possible. It results in a large APK due to files needed to support multiple screen densities or Application Binary Interfaces (ABIs): 'x86', 'armeabi-v7a', 'arm64-v8a', 'x86_64'.

Gradle can create separate APKs that contain only code and resources specific to each density or ABI.

To reduce the APK size, use Gradle to declare the use of multiple APKs that contain specific ABIs files. The ones that are of interest in QiSDK projects are "x86" and "armeabi-v7a" ABIs that match respectively to tablet emulator ("x86") and to the real tablet on Pepper ("armeabi-v7a").

The configuration below builds two distinct versions of your app APK. Each contains only code and resources specific for each density or ABI. This results in a size reduction of the APK (can be more 50%) and thus the install time.

Add the code below in the android section of your build.gradle (Module: app)

splits {
        // Configures multiple APKs based on ABI.
        abi {
            enable true
            reset()
            include "x86", "armeabi-v7a" 
            universalApk false
        }
    }

If you just need the emulator or Pepper tablet's APK keep only the ABI needed in the configuration file.

The APKs are generated in:

  • <your_project_directory>/app/build/outputs/apk/debug if building in debug mode (the default)
  • <your_project_directory>/app/release if building in release mode

Let's check the size reduction using Retail Demo app. Clone it from Github, build the package and compare APK sizes with and without multiple ABI option.

Without multiple ABI option, we get a single 34 Mb APK:

$ ls -hs app/build/outputs/apk/debug/*apk
	34M app/build/outputs/apk/debug/app-debug.apk

With multiple ABI option we get two APKs of 16Mb approximately:

$ ls -hs app/build/outputs/apk/debug/*apk
	15M app/build/outputs/apk/debug/app-armeabi-v7a-debug.apk
	16M app/build/outputs/apk/debug/app-x86-debug.apk

Restrict single APKs ABI's

It is also possible to restrict the set of the ABIs that your application supports and still generate a single APK. By default, all non-deprecated ABI's are added at build time in the APK. We recomment to choose the previous method but this single APKs way is good to know about.

For example, to build for only tablet emulator and Pepper's tablet ABI's set the following configuration in your build.gradle:

android {
    defaultConfig {
        ndk {
            abiFilters 'x86', 'armeabi-v7a'
        }
    }
}

This will result in a single APK with a reduced size that works on both devices.

Have nice builds!

Green Guy with glasses
Louis-Gabriel POUILLOT
Senior Software Engineer