Android 12 Developer Preview is here! Try it out, and give us your feedback!

Configure install-time delivery

Feature modules allow you to separate certain features and resources from the base module of your app and include them in your app bundle. You can then customize delivery options to control when and how devices running Android 5.0 (API level 21) or higher download your app's features.

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 changing the behavior of your app or customizing advanced delivery options, you can do so by creating feature modules that are configured for install-time delivery. That is, you can modularize a feature as a feature module, but not enable advanced options so the feature is available when a user installs your app.

Additionally, it might be useful to create feature modules that you configure for install-time delivery because you have the option to later uninstall that feature if it's no longer required. For example, to reduce the installed size of your app, you can modularize content that's required for training or onboarding, and then uninstall the feature module after the user is set up to use your app.

This section describes how to create a feature module for install-time delivery. Before you begin, make sure you're using Android Studio 3.5 or higher and Android Gradle Plugin 3.5.0 or higher.

Configure a new module for install-time delivery

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

To add a 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 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 Module Download Options section, complete the following:

    1. Specify the Module title using up to 50 characters. 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 feature module’s manifest:

    2. In the dropdown menu under Install-time inclusion, select Include module at install-time. Android Studio injects the following in the module’s manifest to reflect your choice:

      <dist:module ... >
            <dist:install-time />

      If you want to learn how to create a feature module that you can download after app install, read configure on-demand delivery.

    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. That means you can 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" />
  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.

Feature module build configuration

When you create a new feature module using Android Studio, the IDE applies the following Gradle plugin to the module’s build.gradle file.

// The following applies the dynamic-feature plugin to your feature module.
// The plugin includes the Gradle tasks and properties required to configure and build
// an app bundle that includes your feature module.

apply plugin: ''

Many of the properties available to the standard application plugin are also available to your feature module. The following sections describe the properties you should and shouldn’t include in your feature module’s build configuration.

What not to include in the feature module build configuration

Because each feature module depends on the base module, it also inherits certain configurations. So, you should omit the following in the feature module’s build.gradle file:

  • Signing configurations: App bundles are signed using signing configurations that you specify in the base module.
  • The minifyEnabled property: You can enable code shrinking for your entire app project from only the base module’s build configuration. So, you should omit this property from feature modules. You can, however, specify additional ProGuard rules for each feature module.
  • versionCode and versionName: When building your app bundle, Gradle uses app version information that the base module provides. You should omit these properties from your feature module’s build.gradle file.

Establish a relationship to the base module

When Android Studio creates your feature module, it makes it visible to the base module by adding the android.dynamicFeatures property to the base module’s build.gradle file, as shown below:

// In the base module’s build.gradle file.
android {
    // Specifies feature modules that have a dependency on
    // this base module.
    dynamicFeatures = [":dynamic_feature", ":dynamic_feature2"]

Additionally, Android Studio includes the base module as a dependency of the feature module, as shown below:

// In the feature module’s build.gradle file:
dependencies {
    // Declares a dependency on the base module, ':app'.
    implementation project(':app')

Specify additional ProGuard rules

Although only the base module’s build configuration may enable code shrinking for your app project, you can provide custom ProGuard rules with each feature module using the proguardFiles property, as shown below.

android.buildTypes {
     release {
         // You must use the following property to specify additional ProGuard
         // rules for feature modules.
         proguardFiles ''

Note that these ProGuard rules are merged with those from other modules (including the base module) at build time. So, while each feature module may specify a new set of rules, those rules apply to all modules in the app project.

Deploy your app

While you're developing your app with support for feature modules, 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 feature modules, you can choose which 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 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 feature modules, try the following resources.

Blog posts