Android Instant Apps

Learn about Instant Apps and how to implement it to your (existing) Android apps.

Julia Tetens
the peak lab.
7 min readSep 25, 2018

--

Credit: Tommy Tong, Unsplash

Android Instant Apps are native Android apps that can be used without pre-installation. They always belong to an installable app and can not be released without it.

If there is an Instant App for an installable app available, the Play Store displays a “Try Now” button so that the user can try the Instant App directly without installing the whole app.

Instant apps can be linked to web links via Android App Links. So they can be accessed via a web link directly from other apps (for example, from Google Search app, from shared links in social media and messaging apps, etc.). If the installable app already exists on the user’s device, this app is opened directly (no app selection dialog as usual in Android).

Here’s a short video from Google how Instant Apps look like:

Requirements

  • supported by most devices ≥Android 5.0 (many features like Android App Links and several permissions are only available on ≥ Android 6.0)
  • Android Studio ≥3.0
  • Android SDK build tools ≥ 26.x
  • Android SDK Platform Tools ≥25.x
  • Android SDK Tools (latest version)
  • Instant Apps Development SDK (latest version)
  • Support Repository (latest version)
  • all dependencies from the Support Repository (latest versions)
  • adjust permission handling if necessary (not all permissions are available for Instant Apps)
  • the maximum size of an Instant App is 4MB for alpha, beta and production (10MB for internal test)
  • if you use Android App Links, these links must be verified

Building a project with Instant App Support

To deploy Instant Apps, the app project must be modularized so that the build process is separated from the app logic. There are at least three modules needed for this. Every Module has its own build.gradle with specific responsibilities.

Base Feature Module

The Base Feature Module is a module that must exist in every Instant App. It can contain the entire code of the app (if it’s small enough) or just the base code that will be included in all other Feature Modules. It will be marked as baseFeature:

APK Module

The APK Module contains only a build.gradle and a Manifest.xml to build the APK of the installable app are needed. It sets the applicationID of the entire app in the build.gradle:

The package of the installable APK is defined in the Manifest.xml:

Instant App Module

The Instant App Module defines all the modules that this Instant App should contain. It only has a build.gradle where the dependencies are defined:

Further Feature Modules

In addition to the Base Feature Module the project can contain further modules that encapsulate individual features. Although the Base Feature Module may include the entire code of the app, it is best to split the app into separate feature modules. The smaller the binary of a single Instant App, the faster it can be loaded. These modules must apply the feature plugin in the build.gradle:

“Try Now” Button

Use the following filters to define the entry point Activity of the Instant App (if you also use In App Links in your Instant App, you will have to define a default URL described below in the Android App Links Support section):

Prepare project for Instant Apps

Create a new app from scratch with Instant App Support

When you create a new project with Android Studio, you can click on “include Instant App support” directly in the wizard. You can also define the desired host and the route for your main activity (see guidance Create an Instant App).

Integrate Instant App support into existing app

If you want to add Instant App support to an existing app, the project must be modularized. As described in the previous section, you have to create a Base Feature Module, an APK Module and an Instant App Module.

First step: move all the existing app logic to the base feature module and create the APK module (see guidance Convert to app to a base feature module).

Second step: create the Instant App Module (see guidance Convert a feature module to an instant app).

Third step: split the base feature module into smaller feature modules. This will be only necessary if your base feature module is too large but recommended for better user experience.

Android App Links Support

If you want your Instant App to be accessed via a web link, you have to integrate the Android App Links (Android 6.0 or higher) and verify them on your website.

An Android App Link is defined as an Intent filter in the Manifest.xml just like a deep link. In addition, a default URL must be specified, which serves as the entry point for the “Try Now” button.

In addition, you have to store a JSON file on the associated website under the URL https://domain.name/.well-known/assetlinks.json. This file verifies that your Instant App is allowed to be opened instead of the website. The file can be generated using the In App Link Assistant in Android Studio.

Instant App API

There is an Instant App API which you can use to check if the user currently uses the Instant App or the installable version. You also have the possibility to show an installation dialog for the entire App whenever you want.

Optimization

To keep the Instant App as small as possible and not to exceed the maximum size of 4MB, there are the following tips:

  • use APK Analyzer: Android Studio analyzes and uncovers a selected APK, which consumes the most space
  • Code refactoring: remove unnecessary code and outsource as much code as possible to individual modules (right-click on selected files → Refactor → Modularize)
  • Resource refactoring: find unused resources with lint (cmd + alt + shift + I → “unused resources”), convert simple images to .svg and more complex images to WebP (right click on image or whole folder → Converting Images to WebP)
  • Configuration APKs: different APKs can be defined for individual device types, languages ​​etc.
  • Libraries: remove unnecessary libs or make sure that they are only involved in the individual modules, where they are really needed; for larger libraries, which only require small parts, the remainder can be excluded by exclude group in the build.gradle
  • ProGuard: use it to shrink, optimize and obfuscate your code

Test

During development, the Instant App can be started on the device directly by building and launching the Instant App module.

In the App Links Assistant in Android Studio, there is the ability to enter URLs and test whether the desired Instant App is called.

With the Statement List Generator and Tester you can enter the URL and the package name of the app and check if Google has verified the url for this package name.

In the Google Play Developer Console, the Instant App can be uploaded as internal test with a specified list of testers. For this, an installable APK version of the app with the same or a higher version code must already have been uploaded.

Distribution

The Instant App is uploaded to the Google Play Console under “Release Management” → “Android Instant Apps”. It is possible to publish the Instant App for an internal test, an alpha, a beta or a production phase. More detailed instructions can be found here.

Miscellaneous

You can find general FAQ page for developing Instant Apps here.

You can also find a good tutorial video from Google Developer Days 2017 in India here.

Conclusion

Instant Apps are a great way to increase traffic in your app. Trying out the app removes the hurdle of installation. By linking to a web link, the Instant App opens directly, providing the ability to run completely native code from a link.

A major disadvantage is that links to Instant Apps are currently not accessible from Google search inside the browser and search results are not marked as an Instant App at the moment. I tried it out with the apps shown in the video above but I wasn’t able to see these special search results. In Google Search app, as well as clicking on a link from GMail or WhatsApp it works fine.

By restricting permissions, apps that need these permissions can not provide Instant Apps (or only features that don’t need them).

As Google pushes the modularization of apps, it’s worth optimizing apps to this scheme. Google has already announced the Android App Bundles (Android Studio 3.2). App Bundles are modular parts of an APK and can be dynamically exchanged without redeploying the entire APK. This means that the entire app does not have to be re-uploaded during an app update and only this part has to be updated on a device. App bundles should also receive Instant App support in the future. This means that an app bundle can be uploaded for updating the entire app as well as an Instant App at the same time.

--

--

Julia Tetens
the peak lab.

Android Developer since Gingerbread. Working at the peak lab. :)