Optimizing the APK size of Takeaway Driver App with Android App Bundle and WebP

Daniel R.
Just Eat Takeaway-tech
3 min readMar 5, 2019

Reducing the size of the app brings direct benefits and may enable more users to download your app. The app’s updates will be faster, because of the shorter download time and finally, fewer device resources will be wasted. :)

Common practice is to enable shrinking to remove unused code and resources in your release build. Shrinking won’t be described in this blog post but we can strongly recommend to set up the ProGuard and enable code shrinking in your project. ProGuard will optimize the bytecode, obfuscate the remaining classes and methods with short names and remove unused code.

In this blog post, we describe how we switched to Android App Bundle and converted the image recourses to WebP image format. The main goal was to reduce the APK size without spending too much time and effort.

Smaller app size with Android App Bundle

After hearing talk about Dynamic Delivery and Android App Bundle at droidcon London 2018 we became inspired. Leading us to give it a try. It seemed to be a great solution to optimize the APK size and to enable dynamic feature modules. Generated App Bundle will be used by Dynamic Delivery to build and serve APKs that are optimized for each device configuration. Unused code and resources needed for other devices will be removed from the APKs. Resulting in a smaller app download for end-users.

Getting started went quite smoothly. You just need to enroll into app signing by Google Play, install Android Studio 3.2 or higher, add support for Dynamic Delivery in your app, and finally build an Android App Bundle.

Build an Android App Bundle in Android Studio

Instead of using a keystore to sign and upload your app’s APK to Google Play, you can now generate an upload key and sign your new Android App Bundle with it. With bundletool, you can test the generated app bundle locally and see already the difference in APK size. In our case, it was around 50% size saving, which is a great result.

Use WebP file format

In addition, to save even more space, we convert the image resources to WebP image format, without reducing the image quality. We could save another 10% of the original APK size. Android Studio has a nice helper to convert all image resources to WebP image format at once. You just have to right click on your resources folder and select “Convert to WebP…”.

Convert image resources to WebP in Android Studio

In the next step, you can select encoding quality and a few other settings, like to skip resource files, where the encoding result will be larger than the original. For more information, you can read this tutorial.

Further improvements can be achieved through the usage of vector graphics, reducing the native code and Java code. Also, you may consider moving from quite heavy RxJava library to Kotlin coroutines and collection extensions which would cover some of RxJava capabilities, like threading, collection filtering, mapping etc. And for data streams, LiveData in Android architecture library could cover your needs.

Finally, we could save with these two methods around 14 MB or 60% of the original APK size. In the long run, the size reduction can vary for each project however we believe these optimisations will be worth the minimal effort.

We recommend these links for further reading:

Reduce the APK size, best practices from Google

Exploring the Android App Bundle by Joe Birch

Forget RxJava: Kotlin Coroutines are all you need by Vladimir Ivanov

This blog post was written together with Selim Furkan Seyhan

Let us know what you think, drop a comment below! Also, make sure to check out our careers page to discover Tech jobs at Takeaway.com!

--

--