In this series of 3 articles, we will explore some ideas to minimize your app's download and install size. This is the second part of the 10 ideas to reduce your APK size series. Here you can read Part I and Part II.

1. Use nine-patch images

Nine-patch images are a useful tool for reducing the size of Android APKs. These images allow developers to create scalable images that can be resized without losing quality, reducing the need for multiple versions of the same image. This means that fewer images need to be included in the APK, reducing its size and improving performance.

In addition, using nine-patch images can help to improve the user experience of the app. By providing high-quality images that scale well across different devices and screen sizes, developers can ensure that the app looks and performs well on all devices.

However, it's important to note that nine-patch images are not suitable for all types of images. They work best for images with simple shapes and clear borders, and may not be suitable for more complex images or those with intricate details.

2. Avoid images with text inside

Having images in your APK with text inside could be a bad idea if you don't take into account i18n (internationalization) and l10n (localization) considerations to ensure a positive user experience for users in different languages and cultures. You need to make sure that the text inside the image is translated and localized to the user's language.

If the text is part of the image, you are going to need to have one image per user's language, which is going to increase your APK size. A better approach could be trying to extract the text from the image so you can have a single image and internationalize the text.

3. Use vector graphics

Vector graphics are a great way to create icons and other scalable media that can be displayed at any resolution. By using vector graphics, you can significantly reduce the size of your APK file. In Android, VectorDrawable objects represent vector images. With just a 100-byte file, you can generate a high-quality image that is sharp and clear no matter the size of the screen.

However, rendering each VectorDrawable object takes a considerable amount of time, and larger images take even longer to appear on the screen. Therefore, it is recommended that you only use vector graphics when displaying small images.

If you want to learn more about working with VectorDrawable objects, please refer to the documentation on Working with Drawables.

4. Stream media files

Streaming media files is becoming an increasingly popular method of reducing the size of Android APKs. Instead of including all media files in the APK, developers can choose to stream these files on-demand. This means that the media files are not downloaded until they are needed, reducing the initial download size of the app.

One of the key benefits of streaming media files is that it makes the app more accessible to users with limited bandwidth and storage space on their devices. This is particularly important in emerging markets where many users do not have access to high-speed internet or have limited data plans.

Streaming media files can also make it easier to update and maintain the app. By hosting media files on a server, developers can make changes and updates to the files without having to push out a new version of the app. This means that users can benefit from new features and improvements to the media files without having to download a new version of the app.

In addition, streaming media files can improve the overall performance and user experience of the app. By not including large media files in the APK, the app can load faster and use less memory, improving the performance of the app on older or less powerful devices.

Of course, there are also some challenges and considerations when it comes to streaming media files. Developers need to ensure that the app can handle interruptions in the network connection and that the user experience is not negatively impacted by slow or unreliable connections.

5. Native animated image decoding

The NDK ImageDecoder API in Android 12 (API level 31) now has the ability to decode all frames and timing data from images using animated GIF and animated WebP file formats. In Android 11, this API only decoded the first image from animations in these formats.

By using ImageDecoder instead of third-party libraries, APK size can be further reduced and future updates related to security and performance can be leveraged.

For more information on the API, consult the API reference and the sample provided on GitHub.

6. Remove debug symbols from your native libraries

Debug symbols are helpful during the development stage when debugging is necessary. If your application is still in development, it makes sense to use debug symbols. However, when it comes time to create a release build, you can use the arm-eabi-strip tool, which is available in the Android NDK, to remove any unnecessary debug symbols from your native libraries. Once this is done, you can compile your release build without the debug symbols, which will reduce the size of your app's binary files.

For more info, you can read here.

7. Avoid extracting native libraries

To optimize the release version of your app, you can package uncompressed .so files in the APK by modifying the useLegacyPackaging flag in your app's build.gradle file. Setting useLegacyPackaging to false will prevent the PackageManager from copying .so files from the APK to the device's file system during installation. This approach also has the added benefit of reducing the size of updates for your app.

8. Create on-demand modules

The app serving model of Google Play, known as Dynamic Delivery, utilizes Android App Bundles to create and distribute optimized APKs that match the specific device configuration of each user. By doing so, users only download the necessary code and resources required to run the app, resulting in smaller and more efficient downloads. This approach eliminates the need to create, sign, and maintain multiple APKs to cater to various devices, making the app development process more streamlined.

The benefits of Dynamic Delivery also allow you to modularize app features that aren't required at install time by adding dynamic feature modules to your app project and including them in your app bundle. Through Dynamic Delivery, your users can then download and install your app's dynamic features on-demand. Dynamic feature modules allow you to separate certain features and resources from the base module of your app and include them in your app bundle. Through Dynamic Delivery, users can later download and install those components on demand after they've already installed the base APK of your app.

For example, consider a text messaging app that includes functionality for capturing and sending picture messages, but only a small percentage of users send picture messages. It may make sense to include picture messaging as a downloadable dynamic feature module. That way, the initial app download is smaller for all users and only those users who send picture messages need to download that additional component.

You can read more here.

9. Use feature modules for specific devices

To reduce the initial download size of your app, you can configure certain features to be downloaded only by devices that support certain capabilities, such as the ability to take pictures or support augmented reality features.

The Conditional delivery allows you to specify certain user device requirements, such as hardware features, locale, and minimum API level to determine whether a modularized feature is downloaded at app install.

10. Analyze your build with the APK Analyzer

Android Studio provides an APK Analyzer that instantly reveals the makeup of your APK or Android App Bundle. Utilizing the APK Analyzer can shorten the time you spend on debugging problems related to DEX files and resources in your app, as well as minimize the size of your APK. The APK Analyzer is also accessible from the command line through apkanalyzer.

You can follow our DipienMedium Publication for more productivity tools & ideas for Android, Kotlin & Gradle developers.

Support Us

There are different ways to support our work:

  • With Bitcoin Lightning using Alby:
  • With PayPal or a credit card using Ko-fi.

Related Articles

If you enjoyed this article, you might get value out of these as well!