Create an instant-enabled app bundle

You create an Google Play Instant experience by including it as part of
an Android App Bundle. Such a bundle is known as an
instant-enabled app bundle. This document shows you how to set up your
development environment for instant-enabled app bundles, as well as how to
configure, build, test, and publish an instant-enabled app bundle.

Additionally, if you want to test your instant experience locally, get access to
either a physical or virtual device.

Learn about the required execution conditions

Google Play Instant runs instant-enabled app bundles in a special kind of
SELinux sandbox for added security. This sandbox permits a subset of
permissions, as well as limited types of interactions with other apps. The
following sections explain the characteristics of this sandbox in more detail.

Supported permissions and operations

Instant-enabled app bundles can only use permissions from the following list:

Define the correct version codes

The version code of your app's instant experience needs to be less than the
version code of the installable app. The expectation is that users move from the
Google Play Instant experience to downloading and installing the app onto
their device. The Android framework considers this transition to be an app
update.

Note: If the user has the installed version of your app on their device, that
installed version always runs instead of your instant experience. This is true
even if the installed version is an older version of your app compared to your
instant experience.

To make sure that you follow the versioning scheme that users expect, follow one
of these strategies:

Restart the version codes for the Google Play Instant experience at 1.

Increase the version code of the installable APK by a large number, such as
1000, to ensure that there is enough space for your instant experience's version
number to increase.

It's OK to develop your instant app and your installable app in two separate
Android Studio projects. If you do so, however, you must do the following to
publish your app on Google Play:

Use the same package name in both Android Studio projects.

In the Google Play Console, upload both variants to the same application.

Note: The version code isn't a user-facing value and is primarily used by the
system. The user-facing version name has no restrictions.

Update the target sandbox version

Your instant app's AndroidManifest.xml file needs to be updated to target the
sandbox environment that Google Play Instant supports. You can complete
this update by adding the android:targetSandboxVersion attribute to your app's
<manifest> element, as shown in the following code snippet:

Note: A given module can contain multiple activities. For an app bundle to be
instant-enabled, however, the combined download size of the code and
resources within all instant-enabled modules must be at most 15 MB.

Your instant experience remains downloaded on a user's device until the
instant experience cache is cleared, which occurs in one of the following
situations:

The instant experience cache is garbage-collected because the device is
running low on available memory.

The user restarts their device.

If either process occurs, the user must re-download your instant experience
in order to interact with it.

If the system is running very low on storage space, it's possible that your
instant experience's user data is removed from internal storage. Therefore, it's
recommended to periodically sync user data with your app's server so that the
user's progress is preserved.

Add logic for instant experience workflows

After you configure your app bundle so that it supports instant experiences, add
the logic that's shown in the following sections.

Check whether app is running instant experience

If some of your app's logic depends on whether the user is engaged in your
instant experience, call the
isInstantApp()
method. This method returns true if the currently-running process is an
instant experience.

Display an install prompt

If you are building a trial version of your app or game, Google Play Instant allows
you to display a prompt within your
instant experience, inviting users to install the full experience on their
device. To display this prompt, use the
InstantApps.showInstallPrompt()
method, as shown in the following code snippet:

Transfer data to an installed experience

If the user enjoys your instant experience, they might decide to install your
app. To provide a good user experience, it's important
that the user's data is transferred from your instant experience to the full
version of your app.

If the user is using a device that runs Android 8.0 (API level 26) or higher,
and if your app specifies a targetSandboxVersion
of 2, then the user's data is transferred
automatically to the full version of your app. Otherwise, you must transfer the
data manually. To do so, use one of the following APIs:

For users who use devices that run Android 8.0 (API level 26) and higher,
use the Cookie API - sample app

If users can interact with your experience on devices that run Android 7.1
(API level 25) and lower, add support for the Storage API -
sample app

Build the app bundle

You can use either Android Studio or the command-line interface to build your
instant-enabled app bundle.

Note: Instant experiences are available only on devices running Android 5.0 (API
level 21) or higher.

Android Studio

To test your app's instant experience on a local machine using Android Studio,
complete the following steps:

If you have an installed version of your app on your test device, uninstall
it.

In Android Studio, from the installation options that appear on the
General tab of the Run/Debug Configurations
dialog, enable the Deploy as instant
app checkbox.

Select Run > Run in the menu bar, or click Run in the
toolbar, then choose the device where you'd like to test your app's instant
experiences. Your app's instant experience loads on the test device that you've
chosen.

Command-line interface

To test your app's instant experience on a local machine using the command line,
complete the following steps:

If you have an installed version of your app on your test device, uninstall
it.

Sideload and run your instant app on your test device by entering the
following command:

Prepare the uploaded bundle for a release to the internal test track. For
more information, see the support article on how to Prepare & roll out
releases.

Sign into an internal tester account on a device, then launch your instant
experience from one of the following surfaces:

The Try Now button from your app's Play Store listing.

A link from a banner on your app's website.

Note: When you use Google Play's internal test track, the Play Console doesn't
apply the size limits discussed in the Google Play Instant overview.
Therefore, you can test and internally showcase an instant experience, even if
it's larger than 15 MB.

In the Play Console, open Release management > Android Instant Apps, then
navigate to the instant app production track.

Select Update from Library, then select the instant-enabled app bundle
that you've uploaded.

Choose where to publish your instant experience

It's possible to launch an instant experience of your app in a subset of the
countries and regions where people can install your app. This capability is
useful in cases where you want to promote your app's instant experience to
users who reside in a specific set of countries and regions.

Additional resources

To learn more about creating instant experiences and Android App Bundles, see
the following resources: