This guide teaches you how to set up your development environment for working
with instant apps. Next, you learn how to create an instant app, either from the
Create project wizard or from an existing app. You then learn how to run and
debug an Android Studio project containing an instant app. Finally, the guide
provides resources on publishing an instant app.

Modularize an existing app

This section describes how to convert an existing monolithic app to a
modularized one, then how to add instant-enabled functionality to the newly
modularized app.

Create base feature and APK modules

To create instant apps, you first need to create the following modules:

A base feature module, or a feature module that's bundled in every instant
app that you create. This is different from the base
module of an Android App Bundle, which
contains both the instant app experience and the initial installed app
experience.

A minimal module that contains only the shared code that's essential for
building your app's APK file.

After completing the process, your app's build process is separated from your
app's logic, making it possible to convert part of the logic-based module to an
instant app.

Designate your app as a base feature module

When you create an app, it automatically contains a module called "app". This
section describes how to declare your app's logic as part of a base feature
module.

Note: This section only describes how to instruct the Gradle build system to use
feature modules. For information on how to extract workflows from a base feature
module into separate, smaller feature modules, see the guide on how to reduce
the size of your instant
app.

To move your app's logic into a base feature module, complete the following
steps:

Rename your module to something like base.

Update the import statements for your app's resources so that they refer
to the newly-named module.

Open your module's base/build.gradle file and designate
the module as a feature module by making the following change:

Create more feature modules for Google Play Instant

By having feature modules, your app is easier to update. These modules also make
it easier for you to create instant apps, where users can click a link to access
functionality within a particular feature module without having to install your
app.

If you're creating a feature module from scratch, you can add functionality for
Google Play Instant immediately.

To create a new feature module for Google Play Instant, complete these
steps:

In Android Studio, select File > New > New Module...

In the Create New Module window that appears, choose Instant App.
Click Next.

Provide a name for the new feature module. This guide calls it "instant".
Click Finish.

Create default URL

If you provide URL access to your instant app, you must
include a default URL. This URL is the one that's invoked when users click
Try Now in the Google Play Store or when users pin your instant app to a
launcher. Usually, the default URL corresponds to your app's main activity,
found in your app's base feature module.

To add a default URL, include a <meta-data> attribute in the app module that
contains your app's main activity, as shown in the following code snippet:

Run your instant app

You can deploy instant apps onto most devices running Android 5.1 (API level 21)
or higher. If you don't have a test device, read the following section to learn
how you can set up an emulator for running instant apps.

To run the project in Android Studio, do the following:

Open the Project window by clicking View > Tool Windows > Project,
then select Run > Run 'instantapp'.

In the Select Deployment Target window, select the target device on which
you'd like to run the app.

Note: When you run your app locally on a device or emulator, the Android system
displays the default placeholder icon for your app. After you have deployed your
instant app's APK to the Google Play Console, the appropriate icon appears when
the instant app loads.

Set up an emulator that supports instant apps

To set up your emulator for running instant apps, complete the following steps:

Create an Android Virtual Device. To use all
the latest features related to instant apps, configure the device so that it
runs Android 8.1 (API level 27) or later, uses the x86 architecture, and
includes Google APIs.

Note: Make sure that your new virtual device uses the Google Play Store
device profile and doesn't use the x86_64 architecture.