Instruction: Android Instant App creation

#1

This instruction helps you to create Google play Instant App in Defold.

Instruction

Preparation

  1. Download android sdk tools for your platform:
    macOS: https://dl.google.com/android/repository/tools_r25.2.3-macosx.zip
    Windows: https://dl.google.com/android/repository/tools_r25.2.3-windows.zip
    Linux: https://dl.google.com/android/repository/tools_r25.2.3-linux.zip
  2. Unpack, and copy tools folder into android-sdk folder.
  3. Install build tools:

android-sdk/tools/bin/sdkmanager --verbose “build-tools;25.0.3”

Commands for all preparation steps:

mkdir ~/android
cd ~/android
mkdir android-sdk
# Supported: macosx,linux,windows
PLATFORM=macosx
TOOL_VERSION=25.2.3
wget https://dl.google.com/android/repository/tools_r$TOOL_VERSION-$PLATFORM.zip
tar xvf tools_r$TOOL_VERSION-$PLATFORM.zip
mv tools android-sdk/tools
./android-sdk/tools/bin/sdkmanager --verbose "build-tools;25.0.3"

Let’s do it!

  1. Create custom AndroidManifest.xml
  2. Add next two lines into <manifest> tag:
xmlns:dist="http://schemas.android.com/apk/distribution"
android:targetSandboxVersion="2"

How it looks:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="{{android.package}}"
        android:versionCode="{{android.version_code}}"
        android:versionName="{{project.version}}"
        android:installLocation="auto"
        xmlns:dist="http://schemas.android.com/apk/distribution"
        android:targetSandboxVersion="2">
  1. Build apk
  2. Align your apk:

android-sdk/build-tools/25.0.3/zipalign -f -v 4 your_apk_full_path.apk aligned_apk_path.apk

  1. Re-sign your apk:

android-sdk/build-tools/25.0.3/apksigner sign --key path/to/your/key.pk8 --cert path/to/your/certificate.pem aligned_apk_path.apk

  1. Create zip archive with aligned_apk_path.apk (result of step 5)
  2. Now you can upload this zip as android instant app:

Troubleshooting

Your Instant App APKs must be a ‘.zip’ file.

You forgot about step 7, just archive you apk as zip.


Upload failed
Your Instant App APKs do not declare a valid ‘android:targetSandboxVersion’ attribute in their AndroidManifest. Using the ‘com.android.feature’ Gradle plugin to build your Instant App would add this attribute automatically.

You forgot about step 2, add needed lines into AndroidManifest.xml file.


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

You forgot about step 4 and 5. Apk should be aligned and re-signed.


Example.

  1. Open game page in Google play https://play.google.com/store/apps/details?id=com.potatojam.classic.solitaire.klondike
  2. Tap to “Try Now” button
15 Likes

Google Instant Apps Native Extension
Android Instant game: 32-bit worked, 64-bit crashed (SOLVED)
#2

Fantastic! Let’s turn this into a proper manual next week!

4 Likes

#3

Agreed! Should be part of the official docs

2 Likes

#4

I think I need to investigate this feature more deeply before the creation of the manual. Current instruction is just for the basic creation of the instant app, but there are many great features and possibilities that I want to check and then share with our community.

4 Likes

#5

Using this NE we have possibility to check is current app instant app and show the Google Play store window to user with offer to install full version of the app.

1 Like