# Google Instant Apps Native Extension

**URL:** <https://forum.defold.com/t/google-instant-apps-native-extension/48649>\
**Category:** The Defoldmine\
**Created:** [April 7, 2019, 6:43pm UTC](https://forum.defold.com/t/google-instant-apps-native-extension/48649 "2019-04-07T18:43:42Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![AGulev](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/agulev/32/4541_2.png) [@AGulev](https://forum.defold.com/u/AGulev)\
**Post date:** [April 7, 2019, 6:43pm UTC](https://forum.defold.com/t/google-instant-apps-native-extension/48649/1 "2019-04-07T18:43:42Z")

</div>

This forum topic is outdated, please, take a look this post about Google Play Instant:

> [@Google Play Instant support](https://forum.defold.com/t/google-play-instant-support/66606):
>
> 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](https://developer.android.com/topic/google-play-instant)) We’re please to announce Defold support for Google Play Instant. Head over to our new [Google Play Instant manual](https://defold.com/extension-googleplayinstant/) to learn more about how to get started with Google Play Instant for Defold. This is yet another feature from our [2020 roadmap](https://forum.defold.com/t/defold-roadmap-for-2020/64749) and it is part…

> **Old post is available here (outdated)**
>
> [https://github.com/AGulev/instantapp](https://github.com/AGulev/instantapp)
> 
> # Google Instant Apps
> 
> This is [Native Extension](https://www.defold.com/manuals/extensions/) for the [Defold Game Engine](https://www.defold.com) implement [Google Play Instant](https://developer.android.com/topic/google-play-instant/overview) API methods.
> 
> [Here you can find](https://forum.defold.com/t/instruction-android-instant-app-creation/48471) instruction how to build instant app using Defold.
> 
> ## Setup
> 
> You can use the InstantApp extension in your own project by adding this project as a [Defold library dependency](https://www.defold.com/manuals/libraries/). Open your game.project file and in the dependencies field under project add:
> 
> [https://github.com/AGulev/instantapp/archive/master.zip](https://github.com/AGulev/instantapp/archive/master.zip)
> 
> Or point to the ZIP file of a [specific release](https://github.com/AGulev/instantapp/releases).
> 
> ## API
> 
> If you are working on cross-platform application the best practice to check the existence of `instantapp` module, this module exists only in android bundle:
> 
> ```lua
> if instantapp then
> -- call instantapp methods
> end
> 
> ```
> 
> #### `instantapp.is_instant_app()` [Original DOC](https://developers.google.com/android/reference/com/google/android/gms/instantapps/PackageManagerCompat#isInstantApp%28%29)
> 
> Returns true if this application is an instant app.
> 
> ```lua
> if instantapp.is_instant_app() then
> --do something specific for instant app
> end
> 
> ```
> 
> #### `instantapp.show_install_prompt()` [Original DOC](https://developers.google.com/android/reference/com/google/android/gms/instantapps/InstantApps#showInstallPrompt(android.app.Activity,%20android.content.Intent,%20int,%20java.lang.String))
> 
> Shows a dialog that allows the user to install the current instant app.
> 
> ```lua
> if instantapp.is_instant_app() then
> instantapp.show_install_prompt() -- if this is instant app then show install prompt
> else
> -- regular app logic
> end
> 
> ```
> 
> Popup example:
> 
> ![2019-04-07 20 54 02](https://user-images.githubusercontent.com/2209596/55688836-b2f9a500-597d-11e9-8618-c675415983f5.jpg)
> 
> #### `instantapp.get_cookie_max_size()` [Original DOC](https://developers.google.com/android/reference/com/google/android/gms/instantapps/PackageManagerCompat.html#getInstantAppCookieMaxSize%28%29)
> 
> Gets the maximum size in bytes of the cookie data an instant app can store on the device.
> 
> ```lua
> local cookie_size = instantapp.get_cookie_max_size() --number, for example 16384
> 
> ```
> 
> #### `instantapp.get_cookie()` [Original DOC](https://developers.google.com/android/reference/com/google/android/gms/instantapps/PackageManagerCompat.html#getInstantAppCookie%28%29)
> 
> 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.
> 
> ```lua
> local cookie_byte_array = instantapp.get_cookie()
> 
> ```
> 
> #### `instantapp.set_cookie()` [Original DOC](https://developers.google.com/android/reference/com/google/android/gms/instantapps/PackageManagerCompat.html#setInstantAppCookie%28byte%5B%5D%29)
> 
> 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.
> 
> ```lua
> instantapp.set_cookie(bytes)
> 
> ```
> 
> ## Issues and suggestions
> 
> If you have any issues, questions or suggestions please [create an issue](https://github.com/AGulev/instantapp/issues) or contact me: [me@agulev.com](mailto:me@agulev.com)

---

<div class="post-metadata">

**Author:** ![AGulev](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/agulev/32/4541_2.png) [@AGulev](https://forum.defold.com/u/AGulev)\
**Post date:** [April 7, 2019, 6:48pm UTC](https://forum.defold.com/t/google-instant-apps-native-extension/48649/2 "2019-04-07T18:48:41Z")

</div>

I implemented the most important two methods for a first version of the NE, if you need something else just give me know.

---

<div class="post-metadata">

**Author:** ![Oleg\_The\_Evangelist](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/oleg_the_evangelist/32/1596_2.png) [@Oleg\_The\_Evangelist](https://forum.defold.com/u/Oleg_The_Evangelist)\
**Post date:** [April 8, 2019, 11:04am UTC](https://forum.defold.com/t/google-instant-apps-native-extension/48649/3 "2019-04-08T11:04:49Z")

</div>

whoah! This feature was ofter requested all around.

Can you please link to a game or a demo on the Play Store that utilises this NE already?

---

<div class="post-metadata">

**Author:** ![AGulev](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/agulev/32/4541_2.png) [@AGulev](https://forum.defold.com/u/AGulev)\
**Post date:** [April 8, 2019, 11:18am UTC](https://forum.defold.com/t/google-instant-apps-native-extension/48649/4 "2019-04-08T11:18:40Z")

</div>

Unfortunately, for now, I have only a dirty demo in test mode, but I’ll try to do an example later on this week. Also, I wanna add new functions for this NE.

---

<div class="post-metadata">

**Author:** ![ianshk](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/ianshk/32/13302_2.png) [@ianshk](https://forum.defold.com/u/ianshk)\
**Post date:** [April 8, 2019, 11:35am UTC](https://forum.defold.com/t/google-instant-apps-native-extension/48649/5 "2019-04-08T11:35:59Z")

</div>

Epic!!

---

<div class="post-metadata">

**Author:** ![AGulev](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/agulev/32/4541_2.png) [@AGulev](https://forum.defold.com/u/AGulev)\
**Post date:** [May 16, 2019, 8:16am UTC](https://forum.defold.com/t/google-instant-apps-native-extension/48649/6 "2019-05-16T08:16:08Z")

</div>

Interesting fact: players who launched the Google Instant App on a page on Google Play account for approximately 10-20% of the number of players who installed the game.  
In my opinion, this is a pretty good result, considering that we are talking only about organic traffic (from advertising you can launch the Instant app via a direct link).

I didn’t bother much and just using the Instant App extension I check if the game is an instant application, if yes, instead of restarting at the end of the level, I suggest installing the full game (almost the same apk, but on a permanent basis). Even with this approach, the game fits into a 4Mb limit for applications (for games, a 10Mb limit).

 ![JvnhfSAkavw](https://forum-defold.b-cdn.net/uploads/default/original/2X/1/1a1ac800393a79d14112fb2926a8235fc4fbd69b.jpeg)

---

<div class="post-metadata">

**Author:** ![AGulev](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/agulev/32/4541_2.png) [@AGulev](https://forum.defold.com/u/AGulev)\
**Post date:** [May 20, 2019, 10:24am UTC](https://forum.defold.com/t/google-instant-apps-native-extension/48649/7 "2019-05-20T10:24:27Z")

</div>

I’ve released version 1.0.0.  
Added new methods:  
`instantapp.get_cookie_max_size()`  
`instantapp.get_cookie()`  
`instantapp.set_cookie()`

Those methods provide a possibility to communicate between instant application and the main application.

---

<div class="post-metadata">

**Author:** ![jm1175](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/jm1175/32/22254_2.png) [@jm1175](https://forum.defold.com/u/jm1175)\
**Post date:** [October 10, 2020, 3:11am UTC](https://forum.defold.com/t/google-instant-apps-native-extension/48649/8 "2020-10-10T03:11:44Z")

</div>

Hi @AGulev is there any chance you could please provide updated instructions for building the instant app as an AAB in the latest version of Defold? It says [here](https://developer.android.com/topic/google-play-instant/overview) “All new instant experiences must publish with instant-enabled app bundles”.

---

<div class="post-metadata">

**Author:** ![AGulev](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/agulev/32/4541_2.png) [@AGulev](https://forum.defold.com/u/AGulev)\
**Post date:** [October 10, 2020, 6:28am UTC](https://forum.defold.com/t/google-instant-apps-native-extension/48649/9 "2020-10-10T06:28:30Z")

</div>

Yes, of course. I’ll take a look.

---

<div class="post-metadata">

**Author:** ![jm1175](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/jm1175/32/22254_2.png) [@jm1175](https://forum.defold.com/u/jm1175)\
**Post date:** [October 10, 2020, 6:57am UTC](https://forum.defold.com/t/google-instant-apps-native-extension/48649/10 "2020-10-10T06:57:25Z")

</div>

Great thanks!

---

<div class="post-metadata">

**Author:** ![AGulev](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/agulev/32/4541_2.png) [@AGulev](https://forum.defold.com/u/AGulev)\
**Post date:** [October 14, 2020, 6:24am UTC](https://forum.defold.com/t/google-instant-apps-native-extension/48649/11 "2020-10-14T06:24:20Z")

</div>

Hi, here is instruction:

> **[Google Play Instant](https://defold.com/extension-googleplayinstant/)**
>
> This manual explains how to create Google Play Instant game with Defold.

I think you need to add

```lua
<dist:module dist:instant="true" />

```

---

<div class="post-metadata">

**Author:** ![jm1175](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/jm1175/32/22254_2.png) [@jm1175](https://forum.defold.com/u/jm1175)\
**Post date:** [October 14, 2020, 8:57am UTC](https://forum.defold.com/t/google-instant-apps-native-extension/48649/12 "2020-10-14T08:57:04Z")

</div>

Thanks, trying it now. One thing I’m confused about is the version codes. How do I set a seperate version code for the instant app and the installable app? Do I need to have a seperate Defold project for the instant app?

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [October 14, 2020, 9:07am UTC](https://forum.defold.com/t/google-instant-apps-native-extension/48649/13 "2020-10-14T09:07:20Z")

</div>

> [@jm1175](#):
>
> Do I need to have a seperate Defold project for the instant app?

No I don’t think so. You need to manually change the version code when you build. Or if you build from the command line you can script it.
