Movatterモバイル変換


[0]ホーム

URL:


Defold logo




Google Play Instant

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)

GooglePlayInstant

Publishing process

To be able to publish your game as Google Play Instant app you need to set up your project properly:

  • Create a customAndroidManifest.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.

Project settings

  • Download libraries: Project->Fetch Libraries
  • Bundleaab Project->Bundle->Android Application
  • Upload youraab in Google Play Console as Android Instant App

Version codes

Pay attention tothe recommendations about the version codes: Instant Game version code needs to be less than the version code of the installable game.

Project settings

android:targetSandboxVersion=”2”

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.

Technical Requirements

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.

API Usage

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 docs

Returns 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 docs

Shows 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:

2019-04-07 20 54 02

instantapp.get_cookie_max_size()Google Developer docs

Gets 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 docs

Gets 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 docs

Sets 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)

Testing

Testing Instant game

|+-android-sdk  |  +-cmdline-tools    |    +-latest      |      +-bin (from unpacked archive)      +-lib (from unpacked archive)
  • Install the Android build tools:
./android-sdk/cmdline-tools/latest/bin/sdkmanager --verbose "build-tools;29.0.3"
  • Installextra-google-instantapps tools:
./android-sdk/cmdline-tools/latest/bin/sdkmanager --verbose "extras;google;instantapps"
  • Launchapk 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.

Source code

The source code is available onGitHub

API reference

API Reference - instantapp


[8]ページ先頭

©2009-2025 Movatter.jp