How to create dynamic module ?

Dynamic Delivery Feature

This uses an Android app bundle to generate an android app as per user configurations. This user has the power to download only the part of resources that are used by user so that you can create a smaller and optimised version of your app.

So first you have to create a new dynamic module in your project. To create a new dynamic module follow the below steps :

1. Select File > New > New Module from the menu bar.
2. In the Create New Module dialog, select Dynamic Feature Module and click Next.
3. After that, you have to give a Title for your module with a maximum character limit of 50 and select the type of module. The dialog gives you three types of the dynamic delivery feature :
1. Include module at install-time
2. Do not include modules at install-time.
3. Only include module at app install for devices with specified features

Pick one as per your needs. In this example, we are using Option 2 and click on Finish.
Once your module is created you will get the below code in your manifest file (For Option 2):

<manifest package="com.example.tutorials">
<dist:module
        dist:instant="false"
            dist:title="@string/title_tutorials">
        <dist:delivery>
        <dist:on-demand />
        </dist:delivery>
        <dist:fusing dist:include="true" />
    </dist:module>
</manifest>

Changes needed in your build.gradle file :

When you create any dynamic module android studio itself add apply plugin: 'com.android.dynamic-feature' to your build.gradle file.

You have to remove the versionName and versionCode from the build.gradle file because it uses this information from the base module. You also have to remove Signing configurations and minifyEnabled property in your module because all is derived from your base module.

Establish a relationship to the base module 

    Add your dynamic modules to your base modules in your build.gradle file using below code :
android {

    // Specifies dynamic feature modules that have a dependency on base module.
    dynamicFeatures = [":Example"]
}

You can use Configure Install Delivery Module to get step by step explanation.

To know how to use the dynamic feature module in your application (Download and install) then check this link.

Comments