The First Experience of App Bundle

The [“Wake Up Screen”] written in spare time has been iterated over a dozen versions. As a lightweight application, the size is maintained at around 13MB because of the different architectures of the library. I tried the App Bundle this weekend and successfully reduced the app size by about 50%.

What is the App Bundle?

As the official website introduced,

The Android App Bundle is Android’s new, official publishing format that offers a more efficient way to build and release your app. The Android App Bundle lets you more easily deliver a great experience in a smaller app size, which can improve install success and reduce uninstalls. It’s easy to switch. You don’t need to refactor your code to start benefiting from a smaller app. And once you’ve switched, you’ll benefit from modular app development and customizable feature delivery.

In short, after using the App Bundle, the Google Play Store can deliver split applications based on the language, screen density, and architectures of the current device. If you had iOS related experience, you can find that the strategy of the App Store is similar. Based on the App Bundle, Google Play also provides the function of Dynamic Delivery, which can dynamically deliver modules. This has something in common with the plug-in technology that has been popular in previous years.

How to use App Bundle

For the “Wake Up Screen”, the architecture of the application itself is not complicated. Add the following code in the android part of build.gradle .

1
2
3
4
5
6
7
8
9
10
11
bundle {
language {
enableSplit = false
}
density {
enableSplit = true
}
abi {
enableSplit = true
}
}

Each configuration needs to be determined according to the characteristics of the specific application. The “Wake Up Screen” currently supports Chinese(Simplified) and English and the switching function is built within the application, so the language is not split in the above configuration.

Click BuildGenerate Signed Bundle/APK and select Android App Bundle . After compiling, upload the generated .aab suffix file to Google Play Store.

More

Because the previous step is no longer an installation package ending in .apk , it is slightly different in the debug phase. Google Play allows for internal testing, which can be used as a debugging method. When using the App Bundle alone, local debugging via the command line is a more convenient option.

Referring to the steps in this document, we should first download the bundletool , and then use the tool for local debugging and installation.

Specific commands can be found through the documentation. To facilitate debugging, I wrote two shell scripts to simplify the steps, as follows.

Script to generate .apks file from .aab file:

1
2
3
4
5
6
7
8
9
BUNDLE_TOOLS="/Users/symeonchen/******/bundletool-all-0.10.3.jar"
KEY_STORE="/Users/symeonchen/******/KeyOfWakeUpScreen"
KS_PASSWORD="******"
KS_ALIAS="******"
AAB_PATH="/Users/symeonchen/******/WakeUpScreen/app/release/app-release.aab"
APKS_FILE_NAME="/Users/symeonchen/******/WakeUpScreen/app/release/app-release.apks"

rm $APKS_FILE_NAME;
java -jar $BUNDLE_TOOLS build-apks --bundle=$AAB_PATH --output=$APKS_FILE_NAME --ks=$KEY_STORE --ks-pass=pass:$KS_PASSWORD --ks-key-alias=$KS_ALIAS

Script to install the app from .apks file to the currently connected device:

1
2
3
4
5
BUNDLE_TOOLS="/Users/symeonchen/******/bundletool-all-0.10.3.jar"
APKS_FILE_NAME="/Users/symeonchen/******/WakeUpScreen/app/release/app-release.apks"


java -jar $BUNDLE_TOOLS install-apks --apks=$APKS_FILE_NAME