Android App Bundles - Add Play feature delivery support for dex and native features in Buck
Created by: uKetki
Background App Bundle is a new publishing format introduced by the Google team in an effort to reduce the redundant binary elements delivered to all android devices when installing a given app. The approach is to split apk contents such as resources for various screen densities, locale, and native libraries built for different architectures. After splitting, only required sub-components will be delivered for a given device.
Further to this, the Play feature delivery model which is introduced by the Google team relies heavily on app bundles. This is essentially a way to generate and serve optimized APKs by delivering features that are not required at the first launch or not affecting the core flow in a lazy manner. This is also a way to modularize app features and deliver features that are applicable to the specific user group (based on country, preference, etc) in a selective manner.
Existing Buck Support Currently, Buck supports the limited functionality of the App Bundles format. The below table summarizes the existing vs proposed state:
App Bundle | Supported in Buck | Proposed Solution | |
---|---|---|---|
Static Feature delivery | locale | ||
architecture | |||
screen-density | |||
Dynamic Feature Delivery | dex | ||
native libraries | |||
resources | |||
Dynamic Asset Delivery | assets |
The effort is to upstream Uber’s solution of adding dex and native lib support critical for enabling dynamic feature delivery in any Android mobile app built over Buck. The high-level overview of the changes are as follows:
- Create Android Optimiser layer and segregate responsibility of AndroidApkOptimizer and AndroidAabOptimizer
- Redefine configuration and create final dex for a feature and base module
- Resolve duplicate entries from dynamic feature Manifest file post merge_manifest rule
- Add attributes in the manifest added by AGP on the fly, used by play core to uniquely identify the feature and bundletool to generate the bundle file
- Build native lib support
Sample App: To demonstrate the output, I created a PlayFeatureDelivery app which is compatible with both the Gradle and Buck build tool system. The app includes 4 dynamic modules and a base module configured through multiple Play delivery options (README).
With the current Buck state, out of the 5 modules, the generated aab contains only the base module:
.
.
├── BundleConfig.pb
└── base
To easily navigate through the changes, refer to individual tags / releases and the related description, along with:
- Gradle output
- Existing Buck output
- Buck output with the above-mentioned support
As the next steps, I will create individual PR with specific details. Welcome your feedback and suggestions, Thanks!