Paper Football is Instant!

I came back from Google Developer Days 2017 inspired and full of energy, ready to implement something!

During those few days in Krakow, apart from amazing sessions and people, two things happened: first, my small app Paper Football recorded a spike in number of usages as Erik showed it to everybody, and second, Ben gave a talk about Instant Apps. The result of this? I built an instant app for my football game during the weekend.

Read further if you want to see what I did wrong and why it took so long for a small app.

I have to admit, I worked with Instant Apps before but I took a break and was happy to see things have changed, plus tools got incredibly better.

The first step was upgrading Android Studio to 3.0 Beta 5 on my home computer. Before doing anything else I decided this time to start differently. I’ve read the Instant Apps documentation several times in the last months and knew you should start by defining your scenario. In order to speed things up it was ok for my Instant App to be a mirror of the Installed App. Note that I don’t recommend this, but since it is a personal project that I use a lot for experiments it was a good choice. I double checked the requirements and saw I only needed to add App Links and modularize my app.

Implementing App Links was a breeze with the new Android Studio as it does all the work for you if you use the App Links Assistant, which can be accessed from the Tools menu. Although self-explanatory, I did use the documentation to make sure I do it right and everything worked as expected. I have to mention that for publishing the assetlinks.json I used Firebase hosting and I already had the domain in place.

Next step was modularizing the app. Paper Football is very light and used to have one module — app. Before making changes I wanted to refresh my memory and checked the samples. Since there was no reason for me to have multiple features I cloned and studied hello-feature-module. Now I needed an emulator. To be sure I used the correct one I created a new image for Nexus 5X running Android 6.0 (API level 23), x86, with Google APIs as instructed here. I ran the sample, then I started to code.

I decided to rename the app module to features and created two more modules: installed and instant. I used the names from the hello-feature-module sample as I found them suitable. All changes were made mainly in the build.gradle files of each module and the project.

I’m going to mention a few things I found useful:

  1. Adding this task in the project’s build.gradle file helped a lot as before doing it I had some random issues with files not being deleted:
task clean(type: Delete) {
delete rootProject.buildDir
}

2. Having global variables helped as they were now referenced in more places and now I had a min sdk for the Instant App and another one for the Installed App.

ext {
buildTools = ‘26.0.0’
compileSdk = 26
minSdkInstant = 23
minSdk = 15
versionCode 17
versionName ‘0.5.17’
supportLib = ‘25.3.1’
}

3. When I tried my Instant App for the first time it crashed with Crashlytics key being null. I knew I had 2 keys, one used for debug and the other one for release. After trying to understand why it was not working I started to search on Google and found the solution here, at the end of the thread. It’s a short-term one until the bug is fixed, but I was happy it worked.

4. Time to publish the Instant App using Developer Play Console!

Decided to skip Instant app development track and go straight to Instant app pre-release track. Error!

Invalid target sandbox version
PROBLEM: There are versions of the app that have a lower android:targetSandboxVersion. This will result in user data loss when upgrading instant to installed mode.
RESOLUTION: Ensure that the APKs with version codes 14 have the android:targetSandboxVersion attribute set to ‘2’ in the AndroidManifest.xml.

I remembered seeing android:targetSandboxVersion in the sample app, but having the word “sandbox” in it made me think it was not needed for a production app. I added it to the AndroidManifest.xml of the Installed App (installed module). Pushed a new version of the installed app to Beta, tried again to publish the Instant app in pre-release track and everything worked!

5. Played a bit with the instant app and being very excited I decided to roll it out to Production. Pushed the button and got another error:

Non-upgradable to installed app
PROBLEM: Some users of this Instant App APKs will not be eligible for any of the APKs in your installed app.
RESOLUTION: Ensure that the targeting of your Instant App APKs matches the targeting of your APKs.

I checked targetSdkVersion in all modules, all were the same. Checked on internet, nothing helpful. I took a break of a few hours as I was getting nuts. With fresh eyes I checked everything again. Tried 20 times thinking maybe it’s a glitch. Took another break. Later I realised that I haven’t pushed my Installed App version containing android:targetSandboxVersion flag to Production! That version of Installed App was in Beta and I wanted to publish the Instant App to Production. I did it and pushing the Instant App to Production worked!

All in all it was a good experience and the next step is to go back and make the Instant App better. If you try it you’ll notice I put everything in there and although you can play, there is no way to sign in / submit the score / install the app.

Link to Instant App: Send https://game.paper-football.com/play to a chat / email and then open it from your phone. Unfortunately you can’t open it from this page.

Note: To enable Instant Apps on your phone open Settings -> Google -> Instant Apps and toggle feature On. The option is not available on all devices.

Special thanks to Erik and Ben for their immense contribution without even knowing :)