How to build the Flutter Instant App

How to build the Flutter Instant App

  • 08 Nov 2020
  • 14 Mins read

Imagine how great it would be if you could try out apps without even installing them. Yes, you can make it with the awesome Flutter framework!

How does your customer run your app on Google Play without installing it? In this topic, we will guide to release the Flutter Instant App to Google Play Store and optimize the Flutter project to meet all Google Play Instant app requirements.

Flutter Instant App with FluxStore

In this tutorial you’ll learn:

  • How to convert Flutter App to support Instant App Feature from Google.
  • How to Analyze the APK and check the root cause to reduce size.
  • Know how to use the Instant Development SDK to instantly enable your apps.
  • What the App Links are and how to use them in combination with instant apps.

Requirements to follow this guide:

  • Good knowledge of Flutter framework, you may know to set up the basic Flutter example, passed some CodeLab guidelines from Google, and know-how to build the Flutter APK
  • You can try with your own Fluter App but the total final APK file should have a maximum of 10MB, on this topic we are using the FluxStore Pro app which is used to demo throughout the guide.
  • Install the latest Android Studio 3.6 with the Flutter plugins.

1. Analyze APK Size

  • Running the script below script to generate the API files:
flutter build apk --split-per-abi
  • Open the Android Studio app and select Analyze feature from the menu Build > Analyze APK... then select the final output folder build > app > outputs > apk
  • Analyzer is a great tool that is attached to Android Studio to check the APK size. It is enabled default on latest Android Studio 3.6.
  • The Analyzer is the great tool come with Android Studio to check the APK size, it enables default on latest Android Studio 3.6
Screenshot from Analyze APK of Android Studio
  • As you may know, the default Flutter application bundle contains native libraries lipapp.so and libflutter.so, each around 9MB, if we build with the Master Flutter channel the size could be smaller ~0.5 MB. Other heavy resources are from the Assets folder and classes.dex

2. Reduce the APK size

  • Our target is to reduce the app size to under 1MB. In order to do that, there is no choice but to remove some features such as Firebase, Admob, Facebook Ads… this is the before and after update pubspect.yaml library.
  • While reducing the size, please make sure to remove some heavy size asset files as well as compress the image, we use Disk Inventory X to explore the detail files from the app, and ImageOptim to compress the image.

3. Google App Instant Setting Keynote

To convert your Flutter app to the Instant App, make sure to follow the official guide from Google, here is some require keynote:

  1. Install Google Play Instant Development SDK, after installing please check the script ia help to make sure the tool is installed correctly.
Android SDK setting
`ia help` script

2. After installing Instant Development SDK successful, open Android Studio and open the project android folder (it’s not the root Flutter project), right-click to the app folder and select Refactor > Enable Instant Apps Support...

Then you may see some changes from the AndroidManifest.xml file as below, you can edit the file manually if you do not use this menu.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:dist="http://schemas.android.com/apk/distribution"
android:targetSandboxVersion="2"
package="com.inspireui.fluxstore">

<!-- The following declaration enables this module to be served instantly -->
<dist:module dist:instant="true"></dist:module>
...
</application>
</manifest>

3. Open Tools > App Links Assistants and use this tool to verify the app link, to understand more about App Link please check this guide. The final XML file could refer to this Gist

Step 1: add new App Link
Step 2: Generate the assetlinks.json file and copy to your hosting
Step 3: Verify if the app link is working

4. Restart the version codes for the Google Play Instant experience at 1. Also I=increase the version code of the installable APK by a large number (such as 4000, to ensure that there is enough space for your instant experience’s version number to increase).

5. Test the app on the simulator by running this script, make sure to install Instant Development SDK as the above guide.

// Checks an instant app for errors, make sure the total app size belove 10MB, otherwise, you need to reduce the project.
ia check apk-file-path
// Launches an instant app to simulator or your connect device
ia run apk-file-path
Check the Instant Development Folder

6. If you have set up the app successfully, it is ready for upload to Appstore. First, make sure to zip the APK before uploading it. Then, go to Release Management > Android Instant Apps to create the New Release and upload new APK.

4. How To Test Instant App

Search the app on Google Play you can see the “Try Now” button app, it’s possible to click the app without installing it, see the instant app demo:

Hope you enjoyed this article and that it might have been of help for people who had similar needs. Greetings!

Related Posts :