Configure on demand delivery

Dynamic feature modules allow you to separate certain features and resources from the base module of your app and include them in your app bundle. Through Dynamic Delivery, users can, for example, later download and install those components on demand after they’ve already installed the base APK of your app.

For example, consider a text messaging app that includes functionality for capturing and sending picture messages, but only a small percentage of users send picture messages. It may make sense to include picture messaging as a downloadable dynamic feature module. That way, the initial app download is smaller for all users and only those users who send picture messages need to download that additional component.

Keep in mind, this type of modularization requires more effort and possibly refactoring your app’s existing code, so consider carefully which of your app’s features would benefit the most from being available to users on demand.

If you want to gradually modularize app features over time, without enabling advanced delivery options, such as on demand deliver, instead configure at-install delivery.

This page helps you add a dynamic feature module to your app project and configure it for on demand delivery. Before you begin, make sure you're using Android Studio 3.3 or higher and Android Gradle Plugin 3.3.0 or higher.

Configure a new module for on demand delivery

The easiest way to create a new dynamic feature module is by using Android Studio 3.3 or higher. Because dynamic feature modules have an inherent dependency on the base app module, you can add them only to existing app projects.

To add a dynamic feature module to your app project using Android Studio, proceed as follows:

  1. If you haven’t already done so, open your app project in the IDE.
  2. Select File > New > New Module from the menu bar.
  3. In the Create New Module dialog, select Dynamic Feature Module and click Next.
  4. In the Configure your new module section, complete the following:
    1. Select the Base application module for your app project from the dropdown menu.
    2. Specify a Module name. The IDE uses this name to identify the module as a Gradle subproject in your Gradle settings file. When you build your app bundle, Gradle uses the last element of the subproject name to inject the <manifest split> attribute in the dynamic feature module’s manifest.
    3. Specify the module’s package name. By default, Android Studio suggests a package name that combines the root package name of the base module and the module name you specified in the previous step.
    4. Select the Minimum API level you want the module to support. This value should match that of the base module.
  5. Click Next.
  6. In the Configure On-Demand Options section, proceed as follows:

    1. Specify the Module title using up to 50 characters. The platform uses this title to identify the module to users when, for example, confirming whether the user wants to download the module. For this reason, your app’s base module must include the module title as a string resource, which you can translate. When creating the module using Android Studio, the IDE adds the string resource to the base module for you and injects the following entry in the dynamic feature module’s manifest:

      <dist:module
          ...
          dist:title="@string/title_dynamic_feature">
      </dist:module>
      
    2. Check the box next to Enable on demand. Android Studio injects the following in the module’s manifest to reflect your choice:

      <dist:module
          ...
          dist:onDemand="true | false">
      </dist:module>
      

      If you do not enable this option, the dynamic feature is available when a user first downloads and installs your app.

    3. Check the box next to Fusing if you want this module to be available to devices running Android 4.4 (API level 20) and lower and included in multi-APKs. This option is available only if you checked the box next to Enable on demand in the previous step. That means you can enable on demand behavior for this module and disable fusing to omit it from devices that don’t support downloading and installing split APKs. Android Studio injects the following in the module’s manifest to reflect your choice:

      <dist:module
          ...
          <dist:fusing dist:include="true | false" />
      </dist:module>
      
  7. Click Finish.

After Android Studio finishes creating your module, inspect its contents yourself from the Project pane (select View > Tool Windows > Project from the menu bar). The default code, resources, and organization should be similar to those of the standard app module.

After you implement a feature that you want to download on demand, learn how to request it using the Play Core library.

Deploy your app

While you're developing your app with support for Dynamic Delivery, you can deploy your app to a connected device like you normally would by selecting Run > Run from the menu bar (or by clicking Run in the toolbar).

If your app project includes one or more dynamic feature modules, you can choose which dynamic features to include when deploying your app by modifying your existing run/debug configuration as follows:

  1. Select Run > Edit Configurations from the menu bar.
  2. From the left panel of the Run/Debug Configurations dialog, select your desired Android App configuration.
  3. Under Dynamic features to deploy in the General tab, check the box next to each dynamic feature module you want to include when deploying your app.
  4. Click OK.

By default, Android Studio doesn't deploy your app using app bundles to deploy your app. Instead, the IDE builds and installs APKs to your device that are optimized for deployment speed, rather than APK size. To configure Android Studio to instead build and deploy APKs and instant experiences from an app bundle, modify your run/debug configuration.

Additional resources

To learn more about using supporting Dynamic Delivery, try the following resource.

Samples

  • PlayCore API sample, a sample app that demonstrates usage of the PlayCore API to request and download dynamic features.
  • Dynamic code loading sample, which demonstrates three different approaches to safely access code from an installed dynamic feature module.

Codelabs

  • On demand modules, which helps you create an app that downloads and installs dynamic features on demand.

Blog posts

Videos