How can I test In-app updates in Android?

痞子三分冷 提交于 2019-12-18 14:54:30

问题


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?


回答1:


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




回答2:


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




回答3:


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

FakeAppUpdateManager

This has some pre-defined methods.




回答4:


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.




回答5:


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




回答6:


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



回答7:


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.



来源:https://stackoverflow.com/questions/56087064/how-can-i-test-in-app-updates-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!