Build to Dynamic Features
If you are in the Android world, you must have heard about Android Bundle format lately. There was a lot of buzz around this last year and if you have not moved yet, your play store developer page reminds you of bundle benefits every-time you release.
This article is to simplify bundle so you can decide whether it is a good fit or not for your organization. Bundle format is a good example of engineering but not well documented in my eyes.
Bundle — The Birth Story In one line, it is a format of delivery which is user-centric. Sure the line above is complex to digest. Let me simplify it.
Every product has a final binary format. It is apk in the Android context. Apk is the format which Android OS understands how to execute. A user can download an apk from Google Play store, third-party stores OR even from any website.
An apk consists of the code developers wrote along with resources needed to run the app. Resources are images (drawable), strings, assets(music file) etc.
The interesting part is mobile devices and apps are used in every part of the world. The same app can be used in the United States OR Germany. The same app can run on a small phone, a big phone, a tablet OR even a TV. The same app runs on different CPU architecture. There is so much fragmentation in Android from devices to OS version.
To cater to all this, the same app needs to have localized resources (USA, Germany, etc). The same app needs to have resources for different screen sizes. The same app needs to have different binaries for different CPU architectures.
APK used to consist of all of the localized resources, all screen size resources, all CPU architecture binaries, etc. It is very simple to create an APK. One click and you are done.
The solution is simple but like other simple solutions in the Software world, it comes with its drawbacks. The drawback is all the resources are packed in each APK and shipped to users. German users are getting ENGLISH resources and vice versa, Small phones are getting Big phones resources and vice versa. We are directly wasting not only so much bandwidth but memory on users phones as well. If we have something in abundance, it does not mean we should waste it. It means we should divide it among others who lack. Next time when you pass that poor lady, give her food if you can.
Solution 1
One day Google realized something needs to be done. It prepared Google Play store to accept multi apks and allowed developers to generate multi apks using Gradle. You could with build file, generate n apks instead of 1 (n >1). The only catch Google Play did not support the same version number and you needed to write some script to generate apks with different version number and then upload those apks to play store.
This solution was working fine until one day, an engineer said. DRY. DO NOT REPEAT YOURSELF. It means do not have the exact same codebase at multiple places. In this context, it was having the same build methods in different companies.
Secondly, generating and maintaining multi apk was surely harder than 1 apk. Every app company had to come up with their own way of organizing this which simply was not helping their business directly. They could use the same man/woman power somewhere else.
Solution 2
Google said enough is enough. I made this mess. Let me correct it. Instead of you all generating and maintaining the multi-apks, I will do that for you. That’s how Bundle was born.
Little more history
As we know Android OS understands APK format. Before Android 5 (21), one app could have one APK. In Android 5 (21), Google developed a mechanism to support multiple apk for a single app. It is like one apk contains English resources, one apk contains German, one apk contains large display resources, one apk contains medium display resources etc.
The OS was ready to support multiple apks for a single app, it is only the creation of multi apk was painful. Something was needed, Google named it Bundle.
Bundle
As you read before the Android platform supports one app having multiple apks. It could be API level, screen size, CPU architecture, etc. Now is the time to make it better. All you need to do is generate the new binary format (Bundle) and the tool will take care of generating the required APKs. You do not need to mention factors (API, screen, CPU etc). Not only this, tools can take it to the next level and truly generate a lot of apks from one bundle ( by adding more factors like language ). For example, my app bundle has following apks inside.