With Google Play Instant, people can use a game without installing it first. Use it to increase engagement or gain more installs by surfacing your instant game across the Play Store and Google Play Games app. (official Google Play Instant docs)
To be able to publish your game as Google Play Instant app you need to set up your project properly:
AndroidManifest.xml
file (copy the default frombuiltins/manifests/android/AndroidManifest.xml
) and add the following attributes to the<manifest>
element:xmlns:dist="http://schemas.android.com/apk/distribution"android:targetSandboxVersion="2"
The following declaration need to be added right after manifest element:
<dist:moduledist:instant="true"/>
This is what it would look like with the defaultAndroidManifest.xml
:
<manifestxmlns: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"><dist:moduledist:instant="true"/>
Add your customAndroidManifest.xml
in the Android section of yourgame.project file.
Add a dependency to the Google Play Instant extension in yourgame.project file. Add:
https://github.com/defold/extension-googleplayinstant/archive/master.zip
or point to the ZIP file of aspecific release to the Dependencies property.
aab
Project->Bundle->Android Applicationaab
in Google Play Console as Android Instant AppPay attention tothe recommendations about the version codes: Instant Game version code needs to be less than the version code of the installable game.
If you setandroid:targetSandboxVersion="2"
in the main installable game you will be able to access the same files as the instant game (a save file for example). Note that certain restrictions apply to a level 2 sandbox. More information inthe official documentation.
Once an app is installed, you can only update its target sandbox value to a higher value. To downgrade the target sandbox value, you must uninstall the app and replace it with a version whose manifest contains a lower value for this attribute.
Even if you set a differentandroid:targetSandboxVersion
in the installable game and instant game you are still able to useinstantapp.set_cookie()
andinstantapp.get_cookie()
for communication between the game versions.
According to theGoogle Play Instant Technical Requirementsapk
size must be less than or equal to 15 MB. Recommendations for application size optimisation are available in theoptimization manual.
Google Play Instant is only available to Android devices running Android OS 6.0 or higher.
The Google Play Instant extension is accessible through theinstantapp.*
namespace where it wraps JavaPackageManagerCompat methods in a Lua API.
If you are working on a cross-platform application the best practice is to check the existence of theinstantapp
module since this module exists only in an Android bundle:
ifinstantappthen-- call instantapp methodsend
For example:
ifinstantappandinstantapp.is_instant_app()then-- if this is instant app save data for the main app and show install promptlocalcookie_size=instantapp.get_cookie_max_size()ifcookie_size>0theninstantapp.set_cookie(bytes_of_save_data)endinstantapp.show_install_prompt()else-- regular app logicend
instantapp.is_instant_app()
Google Developer docsReturns true if this application is an instant app.
ifinstantapp.is_instant_app()then-- do something specific for instant append
instantapp.show_install_prompt()
Google Developer docsShows a dialog that allows the user to install the current instant app.
ifinstantapp.is_instant_app()theninstantapp.show_install_prompt()-- if this is instant app then show install promptelse-- regular app logicend
Popup example:
instantapp.get_cookie_max_size()
Google Developer docsGets the maximum size in bytes of the cookie data an instant app can store on the device.
localcookie_size=instantapp.get_cookie_max_size()--number, for example 16384
instantapp.get_cookie()
Google Developer docsGets the instant application cookie for this app. Non instant apps and apps that were instant but were upgraded to normal apps can still access this API.
localcookie_byte_array=instantapp.get_cookie()
instantapp.set_cookie()
Google Developer docsSets the instant application cookie for the calling app. Non instant apps and apps that were instant but were upgraded to normal apps can still access this API.
instantapp.set_cookie(bytes)
Download Android SDK command line tools from theofficial download page (scroll to the bottom of the page) or from these direct download links:
macOS:https://dl.google.com/android/repository/commandlinetools-mac-6609375_latest.zip
Windows:https://dl.google.com/android/repository/commandlinetools-win-6609375_latest.zip
Linux:https://dl.google.com/android/repository/commandlinetools-linux-6609375_latest.zip
Unpack the downloaded archive and create the following folder structure:
|+-android-sdk | +-cmdline-tools | +-latest | +-bin (from unpacked archive) +-lib (from unpacked archive)
./android-sdk/cmdline-tools/latest/bin/sdkmanager --verbose "build-tools;29.0.3"
extra-google-instantapps
tools:./android-sdk/cmdline-tools/latest/bin/sdkmanager --verbose "extras;google;instantapps"
apk
as Instant game on your device:android-sdk/extras/google/instantapps/ia run path_to_your_game.apk
More information about debugging on mobile devices available in theDebugging manual.
The source code is available onGitHub
Did you spot an error or do you have a suggestion? Please let us know on GitHub!
GITHUB