How can I test In-app updates in Android?

22,671

Solution 1

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.

Solution 2

This is too late, but it might help other developers.

As of today, in-app-update testing can not be done for a debug build. You don't need to put your apk to PlayStore to test also. The best way to test in-app-update is by using internal-app-sharing.

If you follow the below steps one-by-one, you'll be able to test successfully.

  1. To test the app, a tester has to first enable Internal-App-Sharing in PlayStore, follow this link for the same, How to Enable Internal App Sharing for Android?
  2. If you're brave enough to understand the official documents, then simply follow this link to set-up in-app-update testing in your device, https://developer.android.com/guide/playcore/in-app-updates#internal-app-sharing

Here, I'll be writing the same in easy words.

Once you're done with setting up internal-app-sharing in Play-Store, make sure that you have to upload 2 apks to internal-app-sharing on Play-Console and hence generate 2 links. Both apks will be signed using the same signing-key (need not be the same as the one you use to sign for production, any dummy signing-key would work).

  1. First you upload an apk with in-app-update implementation with lower VersionCode (say, 100) to internal-app-sharing on play console.

To know, How to upload apk to internal-app-sharing on Play-Console, follow this lisk, https://support.google.com/googleplay/android-developer/answer/9844679?visit_id=637437125318137239-1277036129&rd=1

NOTE: make sure, you have uninstalled any preinstalled app with the same package-name in your device.

  1. Now you copy the link of the app you uploaded to internal-app-sharing on the play console and use this link to install the app on your device.

NOTE: Before installing, make sure the email-id you're using on play-store has been added in the mail-list on internal-app-sharing on play-console.

  1. Now, once you've installed the app using the link. Now, you need to again create a new signed apk with higher VersionCode (say, 101). And upload this apk to internal-app-sharing.

  2. Now, copy the link with higher VersionCode from internal-app-sharing. Click on this link on your device, it will take you to play-store but this time, update button will be enabled rather than install button as app is already installed in your device with lower VersionCode.

  3. You don't have to click the update button on PlayStore. You just have to click the link and hence open the screen on PlayStore. Now close PlayStore app.

  4. Now, you can launch the already installed app from your device.

If your implementation of in-app-update is fine, launching the app would appear the dialog from PlayStore for update.

Lastly, don't forget to upvote if it helps you in any way. Keep Coding!

Solution 3

Alternatively you can use this class as a UNIT test for simulation of in-app updates

FakeAppUpdateManager

This has some pre-defined methods.

Solution 4

Take a look at documentation of FakeAppUpdateManager

or try below pre-defined method will help you to test app update available or not.

FakeAppUpdateManager fakeAppUpdateManager = new FakeAppUpdateManager(this);
        fakeAppUpdateManager.setUpdateAvailable(1); // add app version code greater than current version.
        fakeAppUpdateManager.getAppUpdateInfo().addOnSuccessListener(new OnSuccessListener<AppUpdateInfo>() {
            @Override
            public void onSuccess(AppUpdateInfo appUpdateInfo) {
                if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE
                        && appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE)) {
                    System.out.println("checkForAppUpdateAvailability");
                }
            }
        });

Solution 5

In my case, I have done the next steps:

  1. Uninstall original app from device.
  2. Install the app from Google Play Store (I already had my app in Store, but if you don´t have it, you can create an alpha or beta version, without publish it in store).
  3. Unistall the app again.
  4. Generate signed apk with the new feature, with a lower versionCode than Google Play version
  5. Install this apk.

When it starts, it checks the new version in Google Play Store, and shows the assistant for update it. If this solution works in a device but not in anothers, try to log in with the same Google account, and try the 5 steps again in this device. Then you can use your original account again. For some crazy reason, it appears that Google Play "activate" the version control and it returns that a version is available again in the rest of devices.

I don´t know exactly the behaviour...

Share:
22,671
yoonhok
Author by

yoonhok

Updated on August 21, 2021

Comments

  • yoonhok
    yoonhok almost 3 years

    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?