Android Instant Apps empowers local Android applications to keep running the android application without installing it in the android device.
Base feature module : The major module of your instant app is the base component module. All other element modules must rely upon the base element module. The base component module contains shared assets, for example, exercises, sections, and format records. At the point when incorporated with an instant app, this module constructs an element APK. At the point when incorporated with an introduced app, the base component module creates an AAR document.
Features : At an exceptionally fundamental level, apps have no less than one element or thing that they do: find a location on a map, send an email, or read the day by day news as cases.
Feature Modules : To give this on-request downloading of features, you have to separate your app into smaller modules and refactor them into feature modules.
Feature APKs : Each feature APK is worked from a feature module in your project and can be downloaded on request by the user and propelled as an instant app.
Each feature inside the instant app ought to have at least one Activity that goes about as the passage point for that feature. A section point activity has the UI for the feature and characterizes the general user stream. At the point when users dispatch the feature on their device, the entry-point activity is what they see first. A feature can have in excess of one entry-point activity, but it just needs one.
As you find in the figure, both “Feature 1” and “Feature 2” rely upon the base feature module. Thusly, both the instant and installed app modules rely upon the feature 1 and feature 2 modules. Each of the three feature modules are appeared in figure – base feature, feature 1, and feature 2 have the com.android.feature module applied to their build configuration records.
Step 2 : Android Source Code
In this progression, we will change over the existing application module into a shareable feature module. We will then make an insignificant application module that has a dependency on the recently framed feature. Note that this feature module will be incorporated into the Instant App build targets later.
Convert the app module into a feature module called base-feature :-
We start with renaming the module from ‘app’ to ‘base-feature’:
Change Module Type :-
Next, we change the module Compose to Feature module by changing the plugin from com.android.application to com.android.feature and furthermore evacuate applicationId because this is no longer an application module in the base-feature/build.gradle file.
// replace apply plugin: ‘com.android.application’
apply plugin: ‘com.android.feature’
// remove application id
Specify base feature in the project base-feature/build.gradle
baseFeature = true
Create appapk module to build APK file :-
Now that we have changed our source code into a reusable library module, we can make an insignificant application module that will make the APK. From File->New Module
Enter application name “app apk”, leave supported module name (instantappdemo)
Replace compile dependencies in appaapk/build.gradle :-
Change it back to “Android view” and remove the application component from appaapk/src/main/AndroidManifest.xml. It should just contain this single manifest component.
We have just moved the application’s core usefulness into a shareable feature module and we are now prepared to start including the Instant App modules.
Creating the instant app APK :-
The Instant App module is simply a wrapper for all the feature modules in your task. It should not contain any code or resources.
Create an Instant App module :-
Select File -> New -> New Module
Next, we have to refresh the instant app gradle document to rely upon the base feature module.
apply plugin: 'com.android.instantapp'
The instant app does not hold any code or resources. It contains just a build.gradle file.
Now must complete a clean rebuild: Build – > Rebuild project.
Defining App Links :-
Select Tools > App Link Assistant
Now tap on the “Open URL Mapping Editor” button.
Now tap the “+” button.
Create a new URL mapping.
Path: pathPattern, /mainactivity
Activity: .MainActiviy (base-feature)
You have to do same process if you have multiple mapping.
Now select the Run configuration dropdown and choose “Edit Configurations…”
Now select instantapp under Android App.
Replace the text ‘<<ERROR–NO URL SET>>’ with https://yourdomain.com/mainactivity
For mapping on the website browser you have to go and Select Tools > App Link Assistant
Now tap on the “Open Digital Assets Links file Generator”.
Now enter your Site Domain and Application ID
Then select either Signing config or Select keystore file.
Now tap on the “Generate Digital Assets Links file” button.
Now you get the signing file details like above image and you have to upload this file on your domain as a suggested path : https://yourdomain.com/.well-known/assetlinks.json (Your Domain Server must be running with the https(SSL)).
After uploading that on the server you have to hit the “Link and Verify”button.
If you are doing something wrong for file uploading on server then it will give you the error like below image.
After Verifying successfully. Now select instantapp from the Run configuration dropdown and click Run.
Step 3 : Test
Now you can see in the below video that instant app doesn’t get installed and show in the application menu.