- Configure on demand delivery
- Configure a new module for on demand delivery
- Deploy your app
- Additional resources
- Samples
- Blog posts
- Videos
Configure on demand delivery
Dynamic feature modules allow you to separate certain features and resourcesfrom the base module of your app and include them in your app bundle. ThroughDynamic Delivery, users can, for example, later download and install thosecomponents on demand after they’ve already installed the base APK of your app.
For example, consider a text messaging app that includes functionality forcapturing and sending picture messages, but only a small percentage of userssend picture messages. It may make sense to include picture messaging as adownloadable dynamic feature module. That way, the initial app download issmaller for all users and only those users who send picture messages need todownload that additional component.
Keep in mind, this type of modularization requires more effort and possiblyrefactoring your app’s existing code, so consider carefully which of yourapp’s features would benefit the most from being available to users on demand.
If you want to gradually modularize app features over time, withoutenabling advanced delivery options, such as on demand deliver, insteadconfigure at-install delivery.
This page helps you add a dynamic feature module to your app project andconfigure it for on demand delivery. Before you begin, make sure you'reusing Android Studio 3.3 or higher and Android Gradle Plugin 3.3.0or higher.
Configure a new module for on demand delivery
The easiest way to create a new dynamic feature module is by usingAndroid Studio 3.3 or higher.Because dynamic feature modules have aninherent dependency on the base app module, you can add them only to existingapp projects.
To add a dynamic feature module to your app project using Android Studio,proceed as follows:
- If you haven’t already done so, open your app project in the IDE.
- Select File > New > New Module from the menu bar.
- In the Create New Module dialog, selectDynamic Feature Module and click Next.
- In the Configure your new module section, complete thefollowing:
- Select the Base application module for your app project fromthe dropdown menu.
- Specify a Module name. The IDE uses this name to identify themodule as a Gradle subproject in yourGradle settings file. When youbuild your app bundle, Gradle uses the last element of the subprojectname to inject the
<manifest split>
attribute in thedynamic feature module’s manifest. - Specify the module’s package name. By default, Android Studiosuggests a package name that combines the root package name of thebase module and the module name you specified in the previous step.
- Select the Minimum API level you want the module to support.This value should match that of the base module.
- Click Next.
In the Configure On-Demand Options section, proceed as follows:
- Specify the Module title using up to 50 characters. The platformuses this title to identify the module to users when, for example,confirming whether the user wants to download the module. For thisreason, your app’s base module must include the module title as astring resource, which youcan translate. When creating the module using Android Studio, the IDEadds the string resource to the base module for you and injects thefollowing entry in the dynamic feature module’s manifest:
<dist:module
...
dist:title="@string/title_dynamic_feature">
</dist:module>
Note: If you enable resource shrinking, such as for your release builds,the shrinker may remove the module title string resource if code in yourbase module does not reference it. To make sure the string resourceremains in the build output, include the resource in acustom resource keep file.
- Check the box next to Enable on demand. Android Studio injects thefollowing in the module’s manifest to reflect your choice:
<dist:module
...
dist:onDemand="true | false">
</dist:module>
If you do not enablethis option, the dynamic feature is available when a user firstdownloads and installs your app.
- Check the box next to Fusing if you want this module to be availableto devices running Android 4.4 (API level 20) and lower and included inmulti-APKs. This option is available onlyif you checked the box next to Enable on demand in the previousstep. That means you can enable on demand behavior for this moduleand disable fusing to omit it from devices that don’t supportdownloading and installing split APKs. Android Studio injects thefollowing in the module’s manifest to reflect your choice:
<dist:module
...
<dist:fusing dist:include="true | false" />
</dist:module>
- Click Finish.
After Android Studio finishes creating your module, inspect its contentsyourself from the Project pane (select View > Tool Windows > Projectfrom the menu bar). The default code, resources, and organization should besimilar to those of the standard app module.
After you implement a feature that you want to download on demand, learn how torequest it using the Play Core library.
Deploy your app
While you're developing your app with support for Dynamic Delivery, you candeploy your app to a connected device like you normally would by selectingRun > Run from the menu bar (or by clicking Run inthe toolbar).
If your app project includes one or more dynamic feature modules, you canchoose which dynamic features to include when deploying your app by modifyingyour existing run/debug configuration asfollows:
- Select Run > Edit Configurations from the menu bar.
- From the left panel of the Run/Debug Configurations dialog, selectyour desired Android App configuration.
- Under Dynamic features to deploy in the General tab, check thebox next to each dynamic feature module you want to include whendeploying your app.
- Click OK.
By default, Android Studio doesn't deploy your app using app bundles to deployyour app. Instead, the IDEbuilds and installs APKs to your device that are optimized for deployment speed,rather than APK size. To configure Android Studio to instead build and deployAPKs and instant experiences from an app bundle, modify your run/debugconfiguration.
Additional resources
To learn more about using supporting Dynamic Delivery, try the followingresource.
Samples
- PlayCore API sample,a sample app that demonstrates usage of the PlayCore API to request anddownload dynamic features.
Blog posts
- Patchwork Plaid — A modularization story
Videos
- Deliver Features On-Demand with Dynamic Features
上一页
下一页
Configure conditional delivery