Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In-App Update gives InstallException (ERROR_API_NOT_AVAILABLE)

Implemented in-app update feature, using the following code snippet:

private void showInAppUpdateDialog(boolean isMandatoryUpdate) {
    Task<AppUpdateInfo> appUpdateInfoTask = appUpdateManager.getAppUpdateInfo();

    appUpdateInfoTask.addOnSuccessListener(appUpdateInfo -> {
        if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE
                || appUpdateInfo.updateAvailability() == UpdateAvailability.DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS) {

            int appUpdateType = isMandatoryUpdate ? IMMEDIATE : AppUpdateType.FLEXIBLE;
            int requestCode = isMandatoryUpdate ? REQUEST_APP_UPDATE_IMMEDIATE : REQUEST_APP_UPDATE_FLEXIBLE;

            if (appUpdateInfo.isUpdateTypeAllowed(appUpdateType)) {
                // start the app update
                try {
                    appUpdateManager.startUpdateFlowForResult(appUpdateInfo, appUpdateType, targetActivity, requestCode);
                } catch (IntentSender.SendIntentException e) {
                    e.printStackTrace();
                }
            }
        }
    }).addOnFailureListener(e -> {
        e.printStackTrace();
    });
}

I am testing in-app update on the device which has Android 9. Still, it is giving me following an error (ERROR_API_NOT_AVAILABLE):

com.google.android.play.core.install.InstallException: Install Error(-3): The API is not available on this device. (https://developer.android.com/reference/com/google/android/play/core/install/model/InstallErrorCode#ERROR_API_NOT_AVAILABLE)
        at com.google.android.play.core.appupdate.i.a(Unknown Source:24)
        at com.google.android.play.core.internal.o.a(Unknown Source:13)
        at com.google.android.play.core.internal.j.onTransact(Unknown Source:22)
        at android.os.Binder.execTransact(Binder.java:731)

It is saying that check the following link: https://developer.android.com/reference/com/google/android/play/core/install/model/InstallErrorCode#ERROR_API_NOT_AVAILABLE)

Using Play core library version: 1.6.5

Latest core library version:

implementation 'com.google.android.play:core:1.7.0'

However, I am not able to get why it is saying that ERROR_API_NOT_AVAILABLE. Any help would be appreciated!

like image 323
Umang Kothari Avatar asked Mar 17 '20 07:03

Umang Kothari


People also ask

How do I check for app updates on Android?

Use internal app sharing to test in-app updates by performing the following steps: Make sure your test device has a version of your app installed that supports in-app updates and was installed using an internal app sharing URL. Follow the Play Console instructions to share your app internally.

How do I change my app priority update?

To determine priority, Google Play uses an integer value between 0 and 5, with 0 being the default and 5 being the highest priority. To set the priority for an update, use the inAppUpdatePriority field under Edits.


Video Answer


2 Answers

Firstly, please check that you are using the latest version of the play library.

Secondly, understated fact: Please check the app you are testing has the same package name which is available on the play store.

Example:

You have an app on the play store with package name com.example.app but you are testing your app with package name com.example.app.debug. You will get this error: ERROR_API_NOT_AVAILABLE

Note: You need to have at least one version of your app on the play store when you are testing.

like image 75
Vipul Asri Avatar answered Sep 21 '22 07:09

Vipul Asri


On top of what Vipal suggested, the issue may be due to a signature mismatch between the version you have installed on the device and the one that Play Store would deliver (this is a common issue if you try to test it with debug builds). See https://developer.android.com/guide/playcore/in-app-updates#troubleshoot

Recently the Play Core API started returning an API_NOT_AVAILABLE error if the app is not owned by the user or the signatures mismatch, while before it used to return a successful UPDATE_NOT_AVAILABLE Task.

The recommendation is:

  • if you use the Kotlin Extension, make sure that you are catching the exception thrown by requestAppUpdateInfo
  • if you use PlayCore Java, make sure you have an onFailureListener that handles failures from getAppUpdateInfo
  • in order to test a debug build, you can use Internal App Sharing, as explained here: https://developer.android.com/guide/playcore/in-app-updates#internal-app-sharing

Source: I work on the Play Core team

like image 31
Alessandro Dovis Avatar answered Sep 20 '22 07:09

Alessandro Dovis