What’s a DFM?
Speaking of Dynamic Feature Module,
we need to mention a little bit about the Android Application Bundle (*.aab)
format first.
An Android App Bundle is a new upload format that includes all your app’s compiled code and resources, but defers APK generation and signing to Google Play.
Google Play’s new app serving model, called Dynamic Delivery, then uses your app bundle to generate and serve optimized APKs for each user’s device configuration, so they download only the code and resources they need to run your app. You no longer have to build, sign, and manage multiple APKs to support different devices, and users get smaller, more optimized downloads.
– from Google Developer
The most significant benefit of the aab format is to allow Google play store to send different feature combinations and different resource settings of your App to various user devices according to the device hardware spec. That helps to reduce the download time. Why? if users want to use one or two features from your App, they can download the parts they want or the parts they are interested in instead of downloading full feature-set App at one time. This way allows us to decrease the APK size, eliminate the downloading time[1], and increase the App download rate/retention rate.
Let’s see how it works.
You can see the above architecture: developers should separate their features into different feature modules. In this diagram, it has one base module and two different feature modules. The Google play store controls the process of generating different APK packages for users. When a new user tries to download your App. It will process and form a new suitable version to this user like this:
Dynamic Delivery
Here list out the advantages for Android Application Bundle.
- Develop in parallel: By separating logical components of your app into modules, different teams or individuals in your organization can take ownership of each module and work on them with fewer merge conflicts or disruptions to other groups. Additionally, if you have logic included in various parts of your app, you can use library modules to promote code reuse and encapsulation.
- Improve build times: Build systems, such as the Android Studio build system using Gradle, are optimized for projects that are using modules. For example, if you enable Gradle’s parallel project execution optimization on a workstation that includes a multi-core processor, the build system can build multiple modules in parallel and significantly reduce build times. The more modular your project is, the more significant the build performance improvement becomes.
- Customize feature delivery: Modularizing your app’s features as dynamic feature modules is a requirement to take advantage of Dynamic Delivery’s custom delivery options, such as on-demand, conditional, and instant delivery. Creating on-demand dynamic features requires more effort and possible refactoring of your app. So, consider carefully which of your app’s features would benefit the most from being modularized into dynamic features and benefiting from custom delivery options.
Then, here is a crucial point: you need to create your dynamic feature modules first. Let’s do together.
Step 1 - Create a new module
Choose feature module
Remember, there’re several module choices here. We need to select the dynamic feature module
type.
Step 2 - Input related information for your feature module
Input basic information
Input related information for your module, for example, module name, package path, etc.
Step 3 - Choose related properties
Choose properties
Two things need to mention here.
- On-Demand Specifies whether the module should be available as an on-demand download. That is if this attribute sets to
true,
the module is not available at install time, but your app may request to download it later. If this attribute sets tofalse,
the dynamic feature module is included when the user first downloads and installs your app. - Fusing: Specifies whether to include the module in multi-APKs that target devices are running Android 4.4 (API level 20) and lower. Note: only dynamic feature modules that set this property to true are included in the universal APK when you use bundleTool to generate APKs.
So far, you should see a feature module has been added to your project. But it’s sometimes not so easy to create a feature module. You might see the following errors.
Feature module errors
Then, what’s going on? Here’s the reason. In your base module, you might use the productFlavors
to define different build variants.
1 | ... |
All you need to do is to set up the same productFlavors
into your dynamic feature module. Then the problem has been solved.
Ok, then what? How do we download the dynamic feature and track current status? Here you go:
1 | private fun manageFeatureModules() { |
Happy coding.
[Reference]
[References]