43

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?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
yoonhok
  • 2,575
  • 2
  • 30
  • 58

14 Answers14

83

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.

rpattabi
  • 9,984
  • 5
  • 45
  • 53
  • 1
    Re-uploading the same bundle/apk without bumping up the version code - they could have stated this better in the documentation for SURE ! this was my issue! thanks works now :) – Dennis Anderson Apr 06 '20 at 15:18
  • Hey, I used your process, but the update availability is coming as 1(UPDATE_NOT_AVAILABLE) for me everytime. I updated the version code from 2.49 to 2.49.1 and then uploaded the apk. Is there anything else that needs to be considered? – Shivam Pokhriyal Apr 12 '20 at 07:29
  • 1
    Version code is just an integer. What you are trying to change is version name which is only meant for us humans. – rpattabi Apr 13 '20 at 06:32
  • it worked for internal test tracking but does not work for production, still gettind UPDATE_NOT_AVAILABLE – Shikhar May 04 '20 at 07:17
  • @Shikhar I understand that it is not easy to get in-app update prompt in case of production as there are delays and waiting required before Google Play informs the app about the update. I've added a section for testing through alpha, beta, or production track without much waiting. Hope this helps. – rpattabi Jun 04 '20 at 06:51
  • I may be too late for the party, but what about internal track? Can I use it to test in-app-updates? Which variant of your instruction should I use in case of having an internal track as playground for my updates. Thanks in advance – Steyrix Aug 04 '20 at 08:18
  • I think it should be possible to use internal track. But never tried it. Instructions for Alpha should work. If you let me know your results I'll update the answer. – rpattabi Aug 04 '20 at 10:41
  • Can anyone confirm that everything works in production - I mean when the update is available in the store, people receive the popup - not looking at the update page before – Nikola Oct 19 '20 at 14:03
  • 1
    Thank you very much. Internal app sharing is the best for testing this out. I thought I was unable to make it work nor test. – Amg91 Jan 15 '21 at 17:07
13

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!

Abhishek Kumar
  • 4,532
  • 5
  • 31
  • 53
  • Side note: internal version number must be greater than the version number of the public app, otherwise the public version will be installed. – andreszs Apr 08 '22 at 12:12
12

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");
                }
            }
        });
Tushar Lathiya
  • 940
  • 9
  • 26
8

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

FakeAppUpdateManager

This has some pre-defined methods.

Cyph3rCod3r
  • 1,978
  • 23
  • 33
7

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...

fvaldivia
  • 446
  • 5
  • 13
  • 1
    What about the difference in signatures of apk files? Google Play applies it's own signing on apks you're uploading, so apk from step 2 will have different signature than apk from step 4. – Vadim Kotov Nov 21 '19 at 10:45
  • The apk that is located in Google Play should be compiled with the same signature that the new apk that you generate – fvaldivia Nov 21 '19 at 11:29
  • 1
    @fvaldivia If you use [Google Play App Signing](https://support.google.com/googleplay/android-developer/answer/7384423?hl=en), you can't achieve that: Google Play re-signs every APK you're uploading, so there will be a mismatch (you can't sign apk from step 4 with it) – Vadim Kotov Nov 21 '19 at 16:06
  • 1
    If you use Google Play App Signing, check this answer: https://stackoverflow.com/a/59266778/15139 – rpattabi Dec 10 '19 at 12:12
4

Hmm... I found the solution. It is not the same as the demo on the Google I/O 2019 - Developer Keynotes.

I published the signed release apk into the internal developer version. And it works fine.

Or you can publish it on the "Alpha/Beta close test publish".

yoonhok
  • 2,575
  • 2
  • 30
  • 58
  • 4
    I have uploaded to internal app sharing but appUpdateInfo.updateAvailability() always returns 1 i.e UPDATE_NOT_AVAILABLE. – Mangesh Kadam May 17 '19 at 09:06
  • 3
    It's weird... Now I released to public but... it still "UPDATE_NOT_AVAILABLE". Same to me... – yoonhok May 18 '19 at 07:47
  • 2
    try beta upload with version increment it will work. Also make sure you are using same keystore file used for prod release. It will take some time but will work. – Mangesh Kadam May 20 '19 at 11:02
  • Is there any other option to test apk without uploading apk to play store @MangeshKadam – Moorthy May 22 '19 at 10:38
  • @Moorthy - no not sure. But you can try one thing. Try reducing the version code in your current code base which should be less than prod-one. Make sure you are using same prod keystore. You can't check with debug keystore. – Mangesh Kadam May 22 '19 at 17:29
  • 1
    @MangeshKadam reducing the version code doesn't seem to work (with using the prod keystore). – w3bshark May 31 '19 at 17:32
  • I have followed checklist mentioned in the [link] (https://developer.android.com/guide/app-bundle/in-app-updates) If reducing version code not working for you, you can try below options 1. Upload another apk with version code and version name increment from current production code base to beta channel. 2. package name should be exactly matching (one uploaded to beta and one you are testing). 3. You must be logged in to play-store app on emulator. 4. App must be used at-least once for the user's email ID. 5. keystore should be same. 6. Try to force close and restart play-store app. – Mangesh Kadam Jun 03 '19 at 05:45
  • did you find any solution? i applied all the above methods – hiashutoshsingh Sep 19 '19 at 10:26
  • did you find any solution? @spotashu – Aravindhan Gs Sep 24 '19 at 09:14
  • 1
    @AravindhanGs for now i am not going for this solution as of time issue, but i figure out a another way - make your own custom configuration-json file and set minimum build number to which you want to support the user and then call everytime when splash launches and check your build number to config one and perform action then. I want to force update the user as of my need – hiashutoshsingh Sep 24 '19 at 10:49
  • @MangeshKadam it looks like this is not working for Internal App Sharing yet, see [this answer](https://stackoverflow.com/a/56900478/1000551) – Vadim Kotov Nov 21 '19 at 16:09
  • @VadimKotov as per https://issuetracker.google.com/issues/133905204 they have fixed it for internal app sharing as well. – Mangesh Kadam Dec 09 '19 at 11:13
3

I don't know if by this time you already got it down, but after some time testing I figured out that decreasing the versionName is what I needed to do to be able to test it properly, before I'd tested only decreasing the versionCode... I think that the API should be able to handle whenever the versionName or versionCode are out of date, but apparently it doesn't.

Caio Melo
  • 31
  • 4
  • As I said before, I could do the test when I posted the app on Play Store with a certain version and decrease the `versionName` manually on local `build.gradle` and ran it. Without post the app I was not able to make the test properly. – Caio Melo Sep 20 '19 at 13:25
  • 1
    versionName should not make any difference, it's just a human readable version code, and could be anything, including a short poem. – Brill Pappin Jan 26 '22 at 21:07
3
  1. Generate a singed app bundle with lower version and upload it to internal app sharing from play console.
  2. Install the app on your device using the generated link.
  3. Again Generate an app bundle with higher version code and version number than pervious one
  4. Upload it to internal app sharing
  5. Open the newly generated link but do not update app from play store.
  6. Open the old app again.
  7. Now you will be app to see the update popup in your older installed app.

NOTE - App installed with internal app sharing can't be updated to live app even if the version is higher.

I am using this in-app-update library for simplicity.

Divyam Kumar
  • 51
  • 1
  • 3
2

Internal Test Tracks in the Google Play Console are an excellent tool to use when testing In-App Updates.

Gulzar Bhat
  • 1,255
  • 11
  • 13
  • 4
    This would be a better answer if you described the steps needed. – nasch Oct 05 '19 at 02:45
  • 1
    Follow the link https://support.google.com/googleplay/android-developer/answer/3131213?hl=en – Gulzar Bhat Oct 07 '19 at 02:27
  • Publishing to internal test track takes lot of time. It used to be a matter of few minutes, but now it seems to take days! So not practical. – rpattabi Dec 09 '19 at 13:20
1

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 search any application and copy package name and add to your test application package name both are same ).

3.Unistall the app again.

4.Go to your gradle and set lower versioncode like 1.

5.sync

6.Install.

7.Now you will be app to see the update popup in your older installed app.

1

You can use FakeAppUpdateManager as follow:

val appUpdateManager : AppUpdateManager
    if (BuildConfig.DEBUG) {
      appUpdateManager = FakeAppUpdateManager(baseContext)
      appUpdateManager.setUpdateAvailable(2)
    } else {
      appUpdateManager = AppUpdateManagerFactory.create(baseContext)
    }

With this, you’ll use the Play Store’s AppUpdateManager when the app is launched and FakeAppUpdateManager when tested locally.

The number 2 on setUpdateAvailable corresponds to the app version code. It can be any number as long as it’s higher than your version code defined on build.gradle.

Now, to simulate an immediate update:

val fakeAppUpdate = manager as FakeAppUpdateManager
  if (fakeAppUpdate.isImmediateFlowVisible) {
    fakeAppUpdate.userAcceptsUpdate()
    fakeAppUpdate.downloadStarts()
    fakeAppUpdate.downloadCompletes()
    launchRestartDialog(manager)
  }
Mohamed AbdelraZek
  • 2,503
  • 4
  • 25
  • 36
0

For me, the last step of the Troubleshoot section in the docs made it work!

Basically, after you change the version of the app (version name and code), do this:

Make sure the account is eligible and the Google Play cache is up to date. To do so, while logged into the Google Play Store account on the test device, proceed as follows:
Make sure you completely close the Google Play Store App.
Open the Google Play Store app and go to the My Apps & Games tab.
If the app you are testing doesn’t appear with an available update, check that you’ve properly set up your testing tracks.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
sorry_I_wont
  • 639
  • 1
  • 9
  • 16
0
  1. Uninstall the original app from your device
  2. Download the same app from play store
  3. Decrease Version code in Gradle file
  4. syn and install
  5. Now you will check whether the code is working or not
Habiba
  • 1
0

I have done the following steps for testing

-Install the original app from Google Play Store. browse the app and uninstall it.

-Generate signed app with a lower version code(new feature app) than google play store

-install the signed app. this will ask app update.

-These steps worked for me.

Kishan Thakkar
  • 619
  • 6
  • 11