This guide teaches you how to set up your development environment for working with instant apps. You then learn how to create, run, and debug an Android Studio project containing an instant app. Finally, the guide provides resources on publishing an instant app.
Prepare your development environment
In Android Studio, open the Android SDK Manager. On the SDK Platforms tab, make sure that Android 6.0 (Marshmallow) or later is installed.
Then, open the SDK Tools tab, and install the following packages:
- Android SDK Build-Tools 26.x or higher
- Android SDK Platform Tools 25.x or higher
- Android SDK Tools (latest)
- Instant Apps Development SDK (latest)
- Support Repository (latest)
- All dependencies of Support Repository (latest version for each)
Create your instant app project
To create an instant app, complete the following steps:
- Launch Android Studio and create a new project:
- If you haven't opened a project yet, in the Welcome to Android Studio window, click Start a new Android Studio project.
- If you already have a project open, select File > New Project.
- In the Create Android Project window, do the following:
- In the Application name box, enter "My First Instant App".
- In the Company domain box, enter "example.com".
- Leave the Package name as "com.example.myfirstinstantapp".
- Click Next.
- In the Target Android Devices window, do the following:
- Ensure that Phone and Tablet is selected.
- Under the Minimum SDK list, check Include Android Instant App support. Click Next.
- In the Customize Instant App Support window, leave the default settings. Click Next.
- In the Add an Activity to Mobile window, select Empty Activity. Click Next.
- In the Configure Activity window, do the following:
- In the Instant App URL Host box, enter "myfirstinstantapp.example.com" (without the quotation marks).
- In the Instant App URL route box, enter "/hello" (without the quotation marks).
- Keep the default values of the other settings.
- Click Finish.
Android Studio builds and loads your new project's files.
Run your instant app
You can develop instant apps on 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:
- Click the instantapp module in the Project window and then select Run > Run 'instantapp'.
- In the Select Deployment Target window, select your test device or emulator where you'd like to run the app.
Android Studio builds your app, then installs it on your test device or emulator.
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 that runs Android 8.1 (API level 27) or later, uses the x86 architecture, and includes Google APIs.
Start your emulator and log into a test Google account.
In the system's Settings menu, go to Google > Instant Apps and opt into Android Instant Apps.
Debug your instant app
When developing instant apps, you might encounter some errors. This section includes several of the most common situations that you might need to handle.
Load URL in the browser instead of instant app
A common issue when you run an instant app is that the browser tries to load the URL instead of running the instant app. This problem occurs for a variety of different reasons.
To fix this issue, complete these steps:
adb logcatto see if there are any details on why the browser opened instead of your instant app.
The following type of Logcat message is particularly common:
E/AndroidRuntime: FATAL EXCEPTION: IntentService[IapkLoadService] Process: com.google.android.instantapps.devman, PID: 5951 android.database.sqlite.SQLiteConstraintException: UNIQUE constraint failed: Domains.domain (code 1555)
In this situation, clear your DevMan database by running the following command:
$ adb shell pm clear com.google.android.instantapps.devman
Ensure that your URLs are mapped in the
AndroidManifest.xmlfile within your base feature module. In particular, check that each URL being used in your
<intent-filter>uses the correct host, scheme, and path:
<intent-filter android:order="2"> <data android:host="example.com" android:scheme="https" android:pathPrefix="/hello"/> </intent-filter>
Deploy your instant app for publishing
To prepare your instant app for publishing, complete the following steps:
- In Android Studio, select Build > Generate Signed APK...
- In the Generate Signed APK window, choose the instantapp module. Click Next.
- Complete the steps described in the Distribute your instant app article.
- Navigate to the Google Play Console to complete the workflow, as described in the Prepare & rollout releases article. Make sure you upload your instant app APK.
To learn more about how to prepare and roll out your app in the Google Play Console, see Sign your APK.