In App Update API always returns 1 (UPDATE_NOT_AVA

2020-07-10 06:17发布

I am using In-App Update API in the application for Update Application while the new version is available in play store.

module gradle

defaultConfig {
        applicationId "xxx.xxxxx"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode rootProject.ext.vCode
        versionName rootProject.ext.vName
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

Last upload version(Live in Playstore)

vCode = 5
vName = "1.0.4"

project gradle (downgrade it for the testing)

vCode = 4
vName = "1.0.3"

Downgrade this version for the testing update available or not.

MainActivity.kt

class MainActivity : AppCompatActivity() {
    private var appUpdateManager: AppUpdateManager? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        appUpdateManager = AppUpdateManagerFactory.create(this)
    }

    override fun onResume() {
        super.onResume()
            checkForVersionUpdate()
    }


    private fun checkForVersionUpdate() {
            appUpdateManager?.appUpdateInfo?.addOnSuccessListener { appUpdateInfo ->
                if ((appUpdateInfo.updateAvailability() == UpdateAvailability.DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS)) {
                    // If an in-app update is already running, resume the update.
                    startUpdateFlow(appUpdateInfo)
                } else if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE
                        && appUpdateInfo.isUpdateTypeAllowed(IMMEDIATE)) {
                    startUpdateFlow(appUpdateInfo)
                }
            }
    }

    private fun startUpdateFlow(appUpdateInfo: AppUpdateInfo) {
        try {
            appUpdateManager?.startUpdateFlowForResult(
                    appUpdateInfo,
                    IMMEDIATE,
                    this,
                    123)
        } catch (e: InvocationTargetException) {
            e.printStackTrace()
        } catch (e: IntentSender.SendIntentException) {
            e.printStackTrace()
        }
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        if (requestCode == 123) {
            if (resultCode != RESULT_OK) {
                Log.i("Update failed code:", resultCode.toString())
                // If the update is cancelled or fails,
                // you can request to start the update again.
            } else if(resultCode == RESULT_CANCELED)
                checkForVersionUpdate()
        }
    }
}

I last uploaded build in play store with App Bundle(.aab) and Open Beta.

Tried following ways.

  • Sign apk with the same package name.
  • Clear Playstore apk cache and storage.
  • Download apk from playstore and uninstall it from device. then after downgrade version code and sign apk and install it in device. Still not showing update app dialog.

4条回答
成全新的幸福
2楼-- · 2020-07-10 06:30

Make sure:

  1. you install Signed Release version for testing

  2. with the same applicationId as in Play Store (your flavour doesn't have any applicationIdSuffix)

  3. and versionCode is lower

  4. and your app is released (as a tester you can download it)

查看更多
Rolldiameter
3楼-- · 2020-07-10 06:32

Here is how I test my in-app update and it's confirmed working for me everytime I rollout.

I use internal test track and increment version code.

  1. use Google play store to install a version of the testing app (I used internal test track rollout)

  2. rollout another version with higher VERSION CODE on Play Console (the same internal test track)

  3. close both testing app and Google play store (not just back to home, use recent key and swipe them off)

  4. open the Google play store and ensure that testing app has an update available (you can check it under "My Apps & Game" > Installed)

  5. now open the testing app and check for UPDATE_AVAILABLE

This works for me almost immediately after rollout

Android In-App Update Api showing UPDATE_NOT_AVAILABLE

查看更多
Animai°情兽
4楼-- · 2020-07-10 06:35

What is helping me during testing is opening Google play store app and open "My apps & games" position from drawer menu.

Make sure on "Updates" tab your tested application appears in "Updates Pending".

That library in my opinion does not check on some google api is there any update available, but is checking some kind of google play store app cache

hope it helps cheers Wojtek

查看更多
叼着烟拽天下
5楼-- · 2020-07-10 06:57

Contrary to other answers that say that test build must be in release mode or has to be uploaded to Play Console Test track - that is all wrong, nowhere in the documentation there is any mention of any of that.

If you meet requirements API >= 21 && have internet connection and face this issue, do the following to resolve:

  • Confirm that your test build has lower version code than what's in production
  • Clear Storage & Cache for PlayStore app
  • Open play store using account that has previously downloaded the app
  • Navigate to your app listing in PlayStore and confirm that "Update" button is showing.

It seems like a caching issue with PlayStore and above steps refresh it. After that you'll be able to test In App Updates even in debug mode.

查看更多
登录 后发表回答