How can I test In-app updates in Android?

yoonhok picture yoonhok · May 11, 2019 · Viewed 18.7k times · Source

Recently, Google introduced 'in-app updates' in Google I/O 2019.

So I am trying to use it.

val appUpdateManager = AppUpdateManagerFactory.create(this)
val appUpdateInfo = appUpdateManager.appUpdateInfo
appUpdateInfo.addOnCompleteListener {
    val result = it.result
    if (result.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE
            && result.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE)) {

        info("should show update")
        appUpdateManager.startUpdateFlowForResult(
                        result,
                        AppUpdateType.FLEXIBLE,
                        this,
                        1)
    } else {
        info("This is already latest version: ${result.updateAvailability()}")
    }
}

But the result.updateAvailability() is always UpdateAvailability.UPDATE_NOT_AVAILABLE.

To do this, I made a signed release apk with previous version code. But it doesn't work.

According to the demo on the Developer Keynote (16:40 ~ )

He is doing it with the emulator. It looks like debug mode.

How can I do this same thing?

Answer

rpattabi picture rpattabi · Dec 10, 2019

Testing using Internal App Sharing

The right way to test in-app update is to use Internal App Sharing (not to be confused with Internal Testing Track).

  1. First setup your Internal App Sharing with the help of these instructions. Unlike Internal Testing Track, Internal App Sharing makes the app available immediately. So there is no waiting time.
  2. Opt-in to app signing by Google Play. This will allow google play to sign the apk generated for the device from the app bundle you provide. Details here.
  3. Build your app bundle. Through command line, it is simply ./gradlew bundleRelease or ./gradlew bundle<variant>.
  4. Go to https://play.google.com/apps/publish/internalappsharing/ and upload the generated aab file which is under app/build/outputs/bundle/<variant>/. Give a decent name that includes version code.
  5. This will provide a link to copy. Use it to install this bundle to your device.
  6. Bump the version code in your app build.gradle and build another bundle. Note: Version code is integer, that's what is to be incremented. Version name is different and it doesn't matter for this.
  7. Similarly upload this new bundle to Internal App Sharing. Name it with the version code.
  8. This will provide another link. Open the link and this opens google play and you should see "Update" option. Don't click on Update!
  9. Open your app and now you should see in-app update prompt.

If you don't see the prompt and if you had followed these steps exactly, most likely, there is an issue with your code. Add some logging to see what is happening in your code.

In our testing, the following did NOT help to test in-app updates (which were suggested elsewhere):

  • Re-uploading the same bundle/apk without bumping up the version code
  • Decreasing version code to be lower than the published version

Testing using Alpha (closed track)

Once testing through internal app sharing is successful, I still found some trouble testing in-app update through published versions. After some trials, I was able to successfully test through Alpha track. I'm adding the steps here (I'm assuming you're familiar with Google Play console's Alpha closed track and adding yourself as alpha tester list):

  1. Install current version of the app through Google Play. This can be from production track or alpha or beta track. This version should already have in-app update feature implemented as this is the version that is expected to show in-app update prompt.
  2. Ensure that Automatic Update is disabled just for your app. You can do this through menu item of your app's store listing on Google Play app. We disable automatic update because, we really want to update the app through in-app update instead of Google Play updating the app when your device is charging.
  3. Publish a new version (with version code incremented, changing version name won't matter) to Alpha track.
  4. Nowadays, it takes a while before the published version shows up in Google Play. You may have to wait for several hours.
  5. Once it shows up in Google Play store, you may eagerly try opening your app. You'll be lucky if in-app update prompt shows up. Most likely it won't. In-app update may not show up even if you kept on waiting for several more hours and kept restarting your app. By following the remaining steps I didn't have to wait.
  6. Close your app completely.
  7. Close Google Play app completely.
  8. Clear Google Play app cache. I found that storage need not to be cleared, just the cache.
  9. Open Google Play and go to My Apps & Games from navigation pane.
  10. Now Google Play will search for the updates. Your app update should show up. Do NOT update here, of course.
  11. Open your app. In-app update prompt should appear. If not, test your in-app update with internal app sharing (steps in previous section) and ensure there is no problem with your implementation.

I guess similar process should work for Beta (open track) and production tracks as well.

Even after the update is available through Google Play, for the end-users to see in-app update, I think it may take quite some time (days!). Google Play has its own confusing ways. Good luck.