keaukraine
keaukraine

Reputation: 5364

How to create multiple instant apps in single project?

After reading documentation and watching official Google tutorials on instant apps I've found that it is required to have at least one feature module, "minimal module" (the module with shared code) and a full app module. Official manual explains how to create these modules in one workspace, intended to be used for a single app.

However, in our case we have a lot of different apps in single Android Studio project.

I can create some common module ("minimal module" according to official naming, as I understand docs) with support library and some shared code. Actually, this shared code is really minimal and technically the only common code base of a reasonably large size will be support library (instant apps won't event share any common resources other than launcher icon).

Is it possible to configure gradle to generate instant app for each app in this project?

Upvotes: 2

Views: 501

Answers (1)

Hassan Ibraheem
Hassan Ibraheem

Reputation: 2369

This should not be an issue. When instant app guides refer to a module, we are discussing "feature modules" here, not any Gradle module in the project. What you are describing as shared code sounds more like a normal library module.

For each instant app you will need 2 Gradle modules at least. One is a feature module applying the feature Gradle plugin. This one will build the feature APK that gets shipped to users, and you can include any libraries you need, and they will be part of the final APK, just like a normal app.

The second module will be the instant app module, applying the instant app Gradle plugin. This one just depends on that feature module, and builds a ZIP archive of your feature APKs (in your case, with a single feature module, just 1)

Of course you're free to use flavors to build all your instant apps, if you don't want to create these modules repeatedly for all your apps.

It doesn't sound like you will need this, but if you want to split your app into multiple feature modules, mainly to reduce total download size, then you will need to build these feature modules on top of a "base feature" module, that acts like a library for instant apps, but still builds a separate APK.

Upvotes: 4

Related Questions