
14 steps I followed to develop my first Instant App
Step 1 : First, I downloaded Android Studio 3.0 Canary 9 ,which you can download from : https://developer.android.com/studio/archive.html
Step 2 : I Opened SDK manager after installing and made sure I had Instant Apps Development SDK installed.
Step 3 : Created a new project named MyApp with minimum SDK support 23, unchecked the instant app support for now and added a new xml layout with name activity_name.xml which has one textview and button to show the First Feature of my app which is SecondActivity.java and layout is second_activity.xml.


And after that I had app folder created.
Step 4 : As we had discussed already in the Instant App presentation we have one base-feature module in Instant App which we can act both as installable App and Instant App as it contains all the features of our app so I renamed app to base-feature.
Step 5 : I opened build.gradle of base-feature and made the following changes i.e removed application Id and changed apply plugin to feature plus added baseFeature true:
Step 6: Now after that I added added Application Module which will contain my base-feature module.Went to File->New->New Module->Select Phone & Tablet Module->Entered Package Name “myapp” and Application name also “MyApp”->Selected Add no activity (because it will be our container for base-feature and first-feature module)->Click “Finish”.
So far my application package contains MyApp(container for base-feature and firstfeature(not added yet part of base-feature currently) ) ,myapplication package which will be used to run my app as Installable App.
And in manifest file of myapplication just keep manifest tag only(refer snapshot below).
Step 7: In this step I opened build.gradle of myapplication module and added the following:
Step 8: In this step I opened build.gradle of base-feature and added the following:
Step 9: I linked my MainActivity.java and SecondActivity.java to the following URLs for running as an Instant app later and MainActivity.java is my complete application.
For linking this activity to URL go to Tools->App Links Assistant and click on Open URL Mapping Editor.After linking we can run whole app as an Instant app when we hit the following URL in the snapshot below:
And Intent to launch the SecondActivty.java from MainActivity.java is given below:
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse(“http://sachin.com/second"));
intent.setPackage(getPackageName());
intent.addCategory(Intent.CATEGORY_BROWSABLE);
startActivity(intent);
Step 10: So I runned myapplication as an installable app in this step:
And in this step I found app installed on my phone as always and I un-installed the same because I was excited to see the Instant App running on my phone.
Step 11: Now, time was to make Instant App for that I simply right clicked on MyApp and clicked on New Module->selected Instant App->Named it(instantapp) refer snapshot below:
Then I had an another module like this and added the following dependency:
And now selected the instant app from run configuration at the top and runned as an instant app.
This I observed on my device,I had URL of my MainActivity.java asking for opening app and I clicked on Open App (this option I observed while running for first time only and after running again it showed me horizontal progress bar and landed me to MyApp which is instant app)and interesting part was that I had similar kind of experience like we have while using installable app refer snapshots below:




Above are the snapshots of the notification panel while running instant app locally on my device.
Now I navigated the following:
Clicked on instantapp-debug.zip
Finally this is our instant app base feature debug apk which we can upload on play store to launch our whole app as an instant app.
Step 12: In this step I added another feature module by right clicking on MyApp and added firstfeature with no activity added because I was about to refactor the existing code as we know in android instant app we have one base feature module and multiple feature modules.
And android studio had automatically added base dependency in build.gradle of firstfeature module.
Studio had also automatically added firstfeature module in build.gradle of base-feature module.
Step 13: Now I went to build.gradle of myapplication module and added the following dependency:
And same for instantapp module:
Step 14: I moved my SecondActivity.java file from base-feature module to the newly created package in firstfeature module and accordingly made changes in manifest files of both the modules as well.
Now, firstFeature package doesn’t contain anything as I had moved the file to firstfeature module.
Note:
Now, I checked instantapp-debug.zip again and I was excited to see my first two instant apks below:
The second one instant app apk can be uploaded on play store to land user to specific section of my app via URL which I mapped to SecondActivity in above step which I am calling that feature i.e First Feature and by looking at its size we can call it is a very light app.
Congratulation, you have developed your first Instant App.