Dynamic feature module using Android App Bundle

Tram Ho

In this article, we will talk about the dynamic module that allows us to separate certain features and resources from the application’s base module and include them in the application package. Through dynamic delivery, users can then download and install features after they have installed the application’s basic APK.

To understand this in detail, we will consider the basic ringtone application in which users can play and set ringtones on their phones:

Having an “About” fab button in the first image that we found is rarely used by users. So instead of providing this feature with the base APK, we will create a separate dynamic feature module in the base code, where there will be code for Introduction only. For this, we will first add a “dynamic feature module”:

At the last step of this procedure, check both “Enable on-demand” and “Fusing”. Fusing for pre-Lollipop devices does not support the dynamic feature module, the “About” module will be installed and downloaded with the APK base:

Then we can see below that we have our own module added to the project. There is another build.gradle as well as a manifest file.

And don’t forget to establish a relationship with the base module:

Now it’s time to see the download code and install the About module. We will handle this function in the onclick of the About: button.

And in the OnCreate () of MainActivity of the basic feature:

We need to have a listener when requesting to install the About feature in the first code:

But wait, we’ve missed an onSuccessfulLoad () method name, add this implementation:

This will launch the MainActivity feature of the About us feature. The first time it may take a while to launch because the download is required but then it will act as an opportunity.

The significant benefit of this dynamic module is that it reduces the size of the application because we are providing additional features on demand.

And, the important point to note is that we will upload the application package (.aab) instead of .apk for this delivery.

Source: https://medium.com/mindorks/dynamic-feature-module-using-android-app-bundle-d5b163aaf91d

Share the news now

Source : Viblo