Skip to main content

Understand Instant App in Android


Introduction

  •  Instant apps is a new feature from Google on Android Platform.
  •  Native Android apps, without the installation.
  •  Access From Anywhere.
  •  Works on the Latest Android Devices.
  •  Slim down your application
  •  Support deep linking and App links.


Google recently released Instant Apps to developers as part of an effort to help kickoff the next big enhancement to the native app experience in Android. Instant Apps aim to help bring users into the best native app experience as quickly as possible by downloading only parts of an application when they need them. This makes it fast and easy to engage users with great mobile app experiences, even though they do not have the application installed on their devices.



Access From Anywhere:
Instant Apps are triggered by URL intents, meaning that they can be started from anywhere including, search results, social media shares, messages, beacons, NFC and other applications or even other Instant Apps — without needing to install your app first.
URLs mapped to your app features must belong to domains you own. Google verifies its links with a DAL(Digital Assets Link) file, that must be stored in your website, so as to avoid apps to be connected to domains they don’t own in the first place.



Works on the Latest Android Devices:
Android Instant Apps supports the latest Android devices from Android 5.0 (API level 21) through Android 8.0 (API level 26).



Slim down your application:
With Instant Apps, having a lean app is more important than ever before.
Each feature of your Instant App must be under 4MB in size.
reconsidering what your success factors are as well as how you track them; removing unused code; optimizing resources; and properly proguarding your modules can really help slim down your application.



Modularize and refactor your application:




Instant Apps requires developers to split their builds into multiple modules called features. Each feature represents a part of the application that can be downloaded on demand.

Feature modules - are modules that applies the new com.android.feature Gradle plugin. They are simply library projects, producing an aar when consumed by other modules. It’s worth noting that they do not have application IDs because they are just library projects.
gradle:
       

apply plugin: 'com.android.feature'
android {
    ...
}
dependencies {
    implementation project(':base')
    ...
}

       
 


Manifest: The feature module’s manifest is also worth noting because since it is functionally only a part of the full app, its manifest will be merged with others when the project is assembled. So feature module manifests should contain things like Activities that are contained in the module. Each feature manifest should also contain a unique package name for the module.


Base feature module - Every project that uses feature modules must have exactly one base module and every feature module must depend on the base module.
The base feature module can be thought of as the root of your project. It contains the shared code and resources to be used by other modules. The base feature differentiates itself from other features with the property baseFeature set to true.
       

apply plugin: "com.android.feature"

android {
    baseFeature true
    ...
}

dependencies {
    feature project(“:feature”)
    application project(“:app”)
    ...
}

       
 


While not mandatory, it’s recommended that your base feature manifest contain an activity tag that references an activity that implements a default-url metadata.
This tells Android which activity to launch in the event that your Instant App is not opened from a deep link but somewhere like a launcher instead.


APK module - This is the normal build module that we are all familiar with. Now it’s setup to consume the base and feature modules in order to output an apk to be installed on user devices. Since it aims to output an installable artifact this module does have an application ID.
       

apply plugin: 'com.android.application'

android {
    defaultConfig {
        applicationId "com.example.appname.apk"
        ...
    }
    ...
}

dependencies {
  implementation project(":my-base-feature")
  implementation project(":my-feature")
}

       
 
The application manifest here is the result of merging all of the other manifests that it inherits from the other feature modules. As a result its manifest is pretty sparse.


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="com.example.appname.apk">
</manifest>


Instant App module - implements the com.android.instant plugin. The consume feature modules and produce a split APK zip containing all of the features that will go into the Instant App. It’s pretty much an empty shell of a project without a manifest that only implements other features feature modules in the project.
Here’s a sample of an Instant App module build script.


       

apply plugin: "com.android.instantapp"
dependencies {
    implementation project(":my-base-feature")
    implementation project(":my-feature")
}

       
 
Conclusion:

Instant Apps unlock a whole new range of user experiences that Android developers can explore in their apps. Building on this new way of interacting, it’s possible to improve the experience of existing users, as well as expand your reach, attracting new ones. What’s more, complete new use cases can be created. However, it’s important to consider the specifics and goals of each app/business, and how an Instant App can be helpful indeed. Time and effort required to make the necessary changes to the code structure should also be taken into account. Next blog will help you to build your first Instant app.

Thank You.
References:

Comments

Popular posts from this blog

Short explanation on Gradle, minSdkVersion, maxSdkVersion, compileSdkVersion and targetSdkVersion in Android

Gradle : The Android build system compiles app resources and source code, and packages them into APKs that you can test, deploy, sign, and distribute. Android Studio uses Gradle . The Android plugin for Gradle works with the build toolkit to provide processes and configurable settings that are specific to building and testing Android applications. Gradle and the Android plugin run independent of Android Studio. Gradle architecture is shown below. Example: android { compileSdkVersion 27 buildToolsVersion “26.0.2” defaultConfig { applicationId “com.example.checkyourtargetsdk" minSdkVersion 15 targetSdkVersion 27 versionCode 1 versionName “1.0” } } minSdkVersion : minSdkVersion is the lower bound for your app . The minSdkVersion is one of the signals the Google Play Store uses to determine which of a user’s devices an app can be installed on.  your app’s minSdkVersion must be at least as high as your dependencies’ minSdkVe

Google re-branded the support Android libraries to AndroidX

It is important to note, you cannot mix AppCompat and Jetpack in the same project. You must convert everything to use Jetpack if you want to upgrade. The support library artifacts are being deprecated and all future development is going into AndroidX , so there's no avoiding this migration. Alan Viverette sums this up nicely: “There won’t be a 29.0.0, so Android Q APIs will only be in AndroidX” The stable release of 28.0.0 will be the final feature release packaged as android.support . All subsequent feature releases will only be made available as androidx-packaged artifacts. Below tips will give you a clearer transition path. The current version of AppCompat (v28.x) is exactly the same as AndroidX (v1.x). In fact, the AppCompat libraries are machine generated by changing maven coordinates and package names of the AndroidX codebase. For example, android.support.v7.app.AppCompatActivity is now androidx.appcompat.app.AppCompatActivity For a complete listi

Android Beginners Guide

                                                                                                               Android Operation System: Android is an operating system based on Linux with a Java programming interface. It provides tools, e.g. a compiler, debugger and a device emulator as well as its own Java Virtual machine (Dalvik Virtual Machine - DVM). Android is created by the Open Handset Alliance which is lead by Google. Android uses a special virtual machine, e.g. the Dalvik Virtual Machine. Dalvik uses special bytecode. Therefore you cannot run standard Java bytecode on Android. Android provides a tool "dx" which allows to convert Java Class files into "dex" (Dalvik Executable) files. Android applications are packed into an .apk (Android Package) file by the program "aapt" (Android Asset Packaging Tool) To simplify development Google provides the Android Development Tools (ADT) for Eclipse. The ADT performs automatically the conversion f