How We Solve The Sideloading Crash After App Bundle Implementation

Nathaniel Khuana
Sep 13, 2019 · 4 min read

As a technology company, Tokopedia provides many services that make customers’ lives easier. Initially, Tokopedia started with a marketplace where sellers able to meet buyers online. After a few years, we entered digital goods such as top-up phone credit and pay utility bills. All those features are available in a single application, and it is a challenge for us to keep the app download size as small as we can.

Google introduced the App Bundle in 2018 at Google I/O as a new publishing format. This new format aims to reduce the app download size by separating the base and some configuration installations. To create an App Bundle from an existing android application, we only need to update the build.gradle file and don’t need to change the rest of the source code.

The Implementation

Tokopedia has implemented the App Bundle format since early 2019. With this format, we can save more than 25% of download size compared to split apks generally.

But the implementation was not so smooth in the beginning. After we published with App Bundle format, we got several new crashes related to the splash screen. The crashes occurred on random devices and OS versions.

The Problem

After several investigations, we realized that the crash came from the android phone that installed the Tokopedia app from other app stores or shared apk (not from the Play Store). In this article, we will share how to reproduce and prevent the crash from sideloading apk. All source code and apks are available at this link

After several investigations, we realized that the crash came from the android phone that installed the Tokopedia app from other app stores or shared apk (not from the Play Store). In this article, we will share how to reproduce and prevent the crash from sideloading apk. All source code and apks are available at this link

How to simulate the crash

From the sample project, we can see a splash screen with a green android icon. The icon resources are located in each separated screen density folder to make sure every density phone has a high-quality image.

Splash screen with multiple drawable resources folder

To simulate the crash, we need to create an App Bundle first. App bundle can be generated from Android Studio build menu then generate the bundle

Generate App Bundle from Android Studio

After we got the aab file, we can extract it to multiple apk based on its configuration with a bundletool. To extract the App Bundle, we can use the script below:

java -jar bundletool-all-0.9.0.jar build-apks — bundle=AppBundleWithoutCoreLib.aab — output=AppWithoutCoreLib.apks

After the App Bundle extraction, there will be two folders:

  1. Splits folder: contain many configuration apks that will be downloaded for android phone with OS Lollipop and above
  2. Standalones folder: For Android phone with OS pre-Lollipop, Playstore will generate apk with less configuration. This method is similar to split apk
Apks inside of App Bundle (splits folder)
Apks inside of App Bundle (standalones folder)
Comparison splits and standalones apks inside of App Bundle

If we install with base-master.apk from splits folder, the app will crash on the splash screen because the app could not found the resource icon in the installation. And we will get crash with stack trace Resources$NotFoundException

The Solution

In May 2019, Google updated its core library with a new API to prevent a crash from sideloading apk. The API is available from version 1.6.0 and above.

Version 1.6.0 prevent the crash from sideloading

With a simple additional code in the application class, the app will display a popup if the app cannot find the required icon or other configuration.

Additional code in application class
Avoid sideloading apk crash with popup installation failed

As we can see, the app will display popup “installation failed” with options “close” to close the app and “reinstall” which will redirect and ask to reinstall the app on Google Play Store. With this library, we can prevent the crash from sideloading apk.

Conclusion

In conclusion, the App Bundle format able to reduce app download size, but we need to be aware of installation from shared apk and other app stores. We can also simulate the crash by installing the base apk after extract the app bundle using a bundletool. And to prevent the crash, we need to implement the latest play core library and add minimal code in application class.

Tokopedia Engineering

Story from people who build Tokopedia

Nathaniel Khuana

Written by

Technical Architect at Tokopedia | https://linkedin.com/in/nathaniel-khuana

Tokopedia Engineering

Story from people who build Tokopedia

More From Medium

More from Tokopedia Engineering

More from Tokopedia Engineering

More from Tokopedia Engineering

Deciphering the Art of Estimation

More from Tokopedia Engineering

More from Tokopedia Engineering

Backpressure in Reactive Streams

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade