Image for post
Image for post

Configuring your app for Play Feature Delivery

Ben Weiss
Ben Weiss
Nov 10 · 5 min read

This article is available as a video and linked at the end of the post.

The Android App Bundle is the publishing format for Android Applications in the Modern Android Development world.

Apps using it have seen an average file size savings of 15 % on user’s devices compared to a universal apk. You can benefit from these savings and streamlined releases without having to make any changes to your app’s code, simply by switching to an Android App Bundle.

To learn more about how to build your first Android App Bundle, read the previous post in this series.

But you can take matters into your own hands and modularize as well as optimize installation even further using Play Feature Delivery.

Why should you care about a modularized app and Play Feature Delivery?

A modularized app will create clearly defined boundaries between separate parts of your application. This has benefits on multiple levels.

In many cases, you only need to rebuild parts of your app. That allows build times to decrease. With decreased build times and clear boundaries between modules, engineering velocity is likely to improve.

Also, on the Google Play Store we have seen that

In this post you will learn about features of Android App Bundles that enable Play Feature Delivery. These features empower you to decrease your app’s size even further. And I will introduce you to the APIs you can use to deliver features conditionally or on demand as well as multiple configuration options.

You can use Android Studio to take you through the “New Module” flow. But we are going to look under the hood when you go through the flow and how you can change your configuration later on.

Establishing the baseline

When starting to modularize an app using feature modules your baseline is install time modules. Here you are already able to reap in benefits such as improved build speed and engineering velocity.

The base configuration for an install-time module looks like this:

The most important parts are the distribution namespace, xmlns:dist="" and the delivery configuration attribute to be set to install-time.

A module configured like this will be installed on the device when the initial installation is requested.

By default every install-time module will be fused into the base module, which makes them non-removable. If you want to be able to remove an install-time module later on, all you have to do is set the removable attribute’s value to true.

Uninstalling modules can be useful for tutorials, sign up flows or other modules with a large footprint that you want to have available during initial installation but that are likely to be of no further use once the flow is complete.

We provide the PlayCore API to request installation and uninstallation of modules and I will cover it later in this post.

Note for devices before Android Lollipop 5.0

The mechanism that enables feature module installation requires devices to run on Android Lollipop 5.0 or newer. For older versions of Android, the feature module’s content can be placed into the base apk. To enable this explicitly you need to set fusing’s include value to true inside the module tag.

<dist:fusing dist:include=”true”>

Conditional delivery set up

Next to install time delivery, conditional delivery is another way to request a feature module. Installation can depend on either the device’s API level, user’s country or a device’s features.

This is what a fully configured AndroidManifest can look like.

Not all of these conditions will have to be set and it is unlikely that you will have to use all of them in a single module. Let’s go through them step by step.

To set up conditional delivery, add the dist:conditions tag.

You can then declare lower and upper API level bounds by using min-api and max-api.

These are helpful when you have a specific module for certain API levels.

Also, each uses-feature element from the AndroidManifest can be used as an install condition. Using the device-feature attribute, you can make sure a feature is only delivered to a user when their device has the technical capabilities to use a feature.

While, by default each user is able to download every feature wherever an app is available, you can choose to make certain features available only for certain countries. This is a great way to localize your app.
To do so, add the user-countries tag and then the two letter country code for a given country.

When you want a feature to not be available in a specific set of countries, make sure to set dist:exclude=”false”. If you want a feature to be only available set the value to true.

Modules without code

Sometimes, all you have is a large asset that you want to deliver to users, such as a TensorFlow model. In cases where you have no code associated with a feature module, make sure that you set hasCode to false in the module’s AndroidManifest file.

<application android:hasCode="false" />

This will let the compiler know that no dex file should be created.

On demand configuration

To take the exact installation time into your own hands, you can make use of on-demand installation. That means, you can call an API to install the module after the app has been downloaded and installed on the user’s device.
Using on-demand installation saves initial download time and size.

In the AndroidManifest, you will have to set the delivery option to on-demand. Then you can use the PlayCore API to download, install and uninstall modules within your app’s flow.

I recommend you take a look at the PlayCoreKtx sample on GitHub as well as watch the video linked below for a detailed introduction into the on demand delivery section of Play Feature Delivery.

Happy modularizing!

And here’s the video version of this post

Android Developers

The official Android Developers publication on Medium

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store