Instant App — Modular Architecture with Android Gradle Plugin 3.0
Android Apps Without Installation
I like to describe instant apps as Android apps without installation, but what does means?
Let’s say that you click on a recipe link a friend shared with you, the system will take care of download, install and launch the instant app passing the link.
In this way you will see a beautiful native app and not a website.
This totally remove the install friction, and has given surprising results to early adopter.
Vimeo has seen sessions more than double in length (+130% increase) and native app users increase 20%.
NYTimes Crossword is used more frequently and those using the instant app have more than doubled the number of sessions.
Full installation
How do you transform the AIA — Android Instant App — in a full installed app? The AIA SDK has an utility method that display a dialog for the full installation, but when to display it is completely up to you.
For Drop Recipes I just decided to display the install dialog when the user try to perform an action that needs authentication: like favoring a recipe.
How to build a AIA
You don’t need to build a new app, but just adapt your current project, and split it by features.
Each box represent a gradle module in an android project, and has a different purpose.
Base Feature: contains shared code and resources, like MyApplication
and AppTheme
Feature: contains all the code related to a feature, like the `RecipeDetailsActivity` or the VideoPlayerActivity
of a video app
App Module: is like the usual app module, but contains no code just a dependency to all the features and will build the apk to upload in the Play Store
Instant App Module: is similar to the App Module, contains no code and just a dependency that we would like to expose as instant app. this will generate a .zip
file containing an apk for each feature
AIA gradle
Here some slides explaining the code for each build.gradle
in each module
Following the assembleDebug
outputs:
- app-installed looks like an usual apk with a
classes.dex
for the code; - app-instant is a
.zip
file and contains an apk for each feature module.
AIA Issues
It looks quite simple from an high level point of view, but there are many implementation issues, these are just some that I encountered:
- Multi-features not working (fixed last week, Google says)
- 4MB base+feature size limit
- Proguard not working
- ButterKnife/AndroidAnnotation needs workaround for view-injection
- Crashlytics has to be applied in the base.gradle
- Base module resources need to be referenced full-scoped
- Resources in the feature manifest file has to be in the base module
I don’t want focus on these issues, since I think they will be fixed in the next months, especially when third party libraries will better support AIAs. I would rather focus on the main change AIA brings: Multi-Modules project.