Step by step example of Developing and Publishing Android Instant App

Step by step example of Developing and Publishing Android Instant App

Step by step example of Developing and Publishing Android Instant App

What is Instant App?

Android Instant Apps give permission for Android users to run your apps instantly. You can open/run the part of the app or full app without installing the app using the pre-defined url (https only) in the manifest file.  This beautiful feature works only in Android Marshmallow (API 23) or upper version.  The latest Android studio (Version 3+) should be installed in order to work with Instant Apps. In this post i will show you Step by step example of Developing and Publishing Android Instant App.

 

Advantages of Instant App

  • Users no need to install in order to  run the app or part of the app.
  • Easy to access the features.
  • User can verify the app before install.
  • High level user experience (ex :- E-commerce app could redirect purchase page to the app ).
  • User retention.

 

Some important tips about Instant Apps

  • Instant App work only in Marshmallow (API 23) and latest version.
  • You can update your existing app with Instant App feature.
  • You should have both Installable version and Instant app version in one project.
  • Instant App must use “https” url.
  • You cannot use resource files that are big in size inside the instant app module but you can use it in installable module.
  • You can use Billing feature, Location feature and Camera feature in the instant app module.
  • Reading phone number feature is available from API 26.
  • NDK supported in Instant app.
  • 4MB is the allowed size for the instant app (however you should try to keep it more minimal. its easy for users to download and run instant app smoothly.)
  • instant app downloads only base feature and dependent features. So keep your needed resources for the instant features, only inside those feature modules.
  • installed app always preference over instant app.
  • You should verify your domain ownership in google play in order to work publish instant app.
  • Use Google’s smart lock for user identity.

 

Install Instant App Development SDK

In Android studio,

goto Tools -> Android -> SDK Manager -> click the SDK tools tab.

Select the Instant App Development SDK and click “Apply”.

The necessary tool is installed now..!

 

Project Structure

Like other android studio app, Instant app also has many modules.

Step by step example of Developing and Publishing Android Instant App

Base Feature module is important. When you create an Instant App enabled Android project, you can see by default base module created and linked with APK app module and Instant App Module. Base module can be called as base feature module.

 

Step by step example of Instant App

Lets create a new android studio project with Instant App Feature.  i named the project as “InstantAppExample“. In this example app, following modules will be created.

  • App Module.
  • InstantApp Module.
  • Base Feature Module. (This module is important to create APK and InstantApp release.)
  • My Feature Module. (Can be accessed through https://appsgit/myfeature).
  • Other Feature Module (Can be accessed through https://appsgit/otherfeature).

 

 

Step by step example of Developing and Publishing Android Instant App

 

we should check the checkbox in order to enable the Instant App feature of the app.

 

Create our Feature module. Name it as “myfeature”

 

Create new Activity for my feature module.

Type you hosting name and url route. url route should be unique to each feature activity.

Note :- You should type your own hosting name Because you need to verify the ownership when you release to playstore.

 

You have created the project now.!

 

Create a new Module (OtherFeature)

Lets create another feature module. To create new module. Right click on the project and click on module.

 

Select Feature Module from the prompted list.

 

Name the new feature module  as “otherfeature“.

 

Give unique url route for the feature activity.

 

We have created all the modules. Lets implement the logics.

 

Now we have 2 feature modules. Lets see how they are connected to both Instant App and APK App.

..code comes here…

 

Generate Signed APK to upload.

Now goto Build -> Generate Signed APK 

Create Normal APK file first, After that we will create the Instant App final release file.

 

 

Now create the Instant app Final Release file.

 

 

Now both releases are ready to upload,

 

Upload the APK and Instant APKs to the playstore

Create an application in in playstore. Name it as “Instant App Example“.

Fill all the necessary fields in the following sections.

  • App releases.
  • Store listing.
  • Pricing&Distribution
  • Upload the screenshots
  • Upload the High Resolution icon.
  • Upload feature graphics.

Next upload the APK file as you do it for normal app.

 

Before we upload the Instant App APK files, lets validate our Host URL name..

 

Verify Android App Links for Instant App

This is the most important part in the Instant App Process.

In Instant App, Android App Links in the intent filter are a special type of deep link that allow your website URLs to open the particular feature in your Android app (Without installing the android app in the device.). We should verify that the both App and the hosting url is owned by us.  Check the android documentation for more info.

<intent-filter android:autoVerify="true">
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data
        android:scheme="https"
        android:host="appsgit.com"
        android:pathPrefix="/otherfeature" />
    <data
        android:scheme="http"
        android:host="appsgit.com"
        android:pathPrefix="/otherfeature" />
</intent-filter>

 

appsgit.com/myfeature or appsgit.com/otherfeature urls are unknown yet.

 

Create Digital Asset Links JSON file.

To Digital assets link the host url do the following steps carefully.

  • Goto your hosting and create a new folder in the root and name it as “.well-known
  • Create a files called “assetlinks.json”  inside the created folder.

Create a content like following format in the asset links.json file,  Don’t forget to change package_name and sha256_cert_fingerprints fields.

[{
  "relation": ["delegate_permission/common.handle_all_urls"],
  "target": {
    "namespace": "android_app",
    "package_name": "your.base.module.manifest.package.name.",
    "sha256_cert_fingerprints":
    ["14:6D:E9:83:C5:73:06:50:D9:EE:B9:95:2F:34:FC:64:16:A0:83:42:E6:1D:BE:A8:8A:04:96:B2:3F:CF:44:E5"]
  }
}]

package_name : The application ID declared in the base module build.gradle file.

sha256_cert_fingerprints :  The SHA256 fingerprints of your app’s  release keystone signing certificate. You can use the following command to generate the fingerprint via the Java keytool:

$ keytool -list -v -keystore your-release-key.keystore

 

Save the file and check the url whether everything is perfectly done.

https://domain.name/.well-known/assetlinks.json

 

If you have a wordpress hosting, don’t forget to enable it in robots.txt file like below,

 

Upload Instant APKs to the playstore

Create Instant App Pre-Release. and then upload the zip file.

 

You should have at least one APK for your installed app before you can create an instant app release.

Upload the already generated Zip file.

 

 

These Instant App APKs will be able to access by testers after the rollout of this release.

 

Now send the Opt-in url to testers. they will be able to test the pre release version.

 

 

Enable Instant App Feature in Android device.

To enable Instant App goto Settings -> google -> instant App  

there you can enable it.

 

Thats all my friends,

 

Test AppsGit Example

Open this post in any of the instant app supported android device and click the https://appsgit.com/myfeature to test the feature.

 

 

Possible Errors & solutions

Provision failed with message: The device used is not whitelisted for instant Apps deployment. Detected Device is:……………………………

 

Solution :- Moslty happens when you try to run in simulators or genymotion. Try to run the app in a latest Marshmallow (API 23+) real device.


Problem

Side loading instant app failed: Failure when trying to read bundle. Failed to parse app: /data/local/tmp/aia/instant-release.zip
Error while Uploading and registering Instant App

Solution

Project is not signed properly.


Problem

E/AndroidRuntime: FATAL EXCEPTION: IntentService[IapkLoadService] Process: com.google.android.instantapps.devman, PID: 5951 android.database.sqlite.SQLiteConstraintException: UNIQUE constraint failed: Domains.domain (code 1555)

Solution

Check the domain name you have mentioned in the manifest file. You should do some alteration there in order to run the app.


Problem

Upload failed

You uploaded an APK with an invalid signature (learn more about signing). Error from apksigner: ERROR: NO_SIG_FOR_TARGET_SANDBOX_VERSION: Missing APK Signature Scheme v2 signature required for target sandbox version 2

Solution:  You should enable V2 sign.


Upload failed

You should use both http and https as schemes for your web intent-filters.


Upload failed

Your Instant App APKs do not declare at least one web ‘intent-filter’ element with the attribute ‘android:autoVerify’ set to true in the Android Manifest.


Errors

Resolve these errors before starting the rollout of this release.

The default URL ‘https://appsgit.com’ does not map to your Instant App
You should publish your app before you create an instant app release.
You should publish at least one production APK before you can publish a production instant app.
Your site ‘appsgit.com’ could not be reached at this time to verify it has been linked through the Digital Assets Link protocol to your app. Check your site’s URL and try again later.
You should have at least one active APK that is mapped to site ‘appsgit.com’ via a web ‘intent-filter’.
Solution
You should rollout your APK file first.

Problem

Your site ‘www.appsgit.com’ has not been linked through the Digital Assets Link protocol to your app. Please link your site through the Digital Assets Link protocol to your app.

Solution

Make sure you have added “assetlink.json”  file in your hosting and particular content is valid.

 

 

Thats all my friends…!

 

Let me know via comment if you have any questions.

 

 

To become a master in android developer, please follow the following online course. i highly recommend it for you.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.