21

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!

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Umang Kothari
  • 3,674
  • 27
  • 36

7 Answers7

12

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.

Vipul Asri
  • 8,903
  • 3
  • 46
  • 71
  • 1. Using latest version of play library 2. Package Names are the same Still, facing this issue :( – Umang Kothari Mar 17 '20 at 14:13
  • It works fine for the Release build, but runs once on Debug version only if you clear your Play Store cache and storage. To run it again, you have to clear the cache and storage of Play Store again. – Abdul Mateen Mar 17 '20 at 15:48
  • 1
    oh this actually worked for me. I cleared cache and store data of Play Store. Thank you @AbdulMateen – gmartinsnull Mar 19 '20 at 01:06
  • I think that the issue is also related to the certificate uploaded to play console. The debug version has a different certificate and it doesn't match with the "production" one. So it's impossible to test the api even with FakeUpdateManager – Nicola Gallazzi Mar 27 '20 at 12:12
12

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:

Source: I work on the Play Core team

  • Using internal app sharing helped me a lot. I can recommend it. A bit cumbersome, but ensures none of those "I make no sense" error messages pop up. – MartinJH Apr 22 '20 at 14:04
  • not work, i multiple times tried it. i use internal app sharing, and lower version code from live playstore and lowered version from previous internal app version. still ERROR_API_NOT_AVAILABLE my certificate from release keystore, google play keystore, debug, internal sharing still not work. please make clear documentation, i really frustrated – Jetwiz May 22 '20 at 18:16
  • I refused to believe this was the case, because the API is working and available in my emulator at work. However, when testing at home, with identical versions of everything, this error keeps showing up when testing an app not installed from the store. This answer is correct in most scenarios. – andreszs Apr 14 '22 at 23:13
2

My app was working fine before today, but I started getting this error today. One temporary workaround is to clear your Google Play Store cache and storage and then try launching the app. For me, it works only the first time, but fails afterwards. Before launching the app again, I have to clear the cache and storage again. I think there is something wrong on Google Play Store side due to which this issue is happening because everything was fine for me before today.

Abdul Mateen
  • 1,418
  • 1
  • 14
  • 32
1

Got the same error, tried all solutions described here, nothing works. App installed from Play Store Internal Test track with Version Code 267, then submitted new update to the same track with Version Code 268.

Play Store shows available update but the application still says ERROR_API_NOT_AVAILABLE

Clear Play Store data and cache does not help.

Description of ERROR_API_NOT_AVAILABLE say that it means “API is not available on device”

After carefully reading again this page, I have noticed that “in-app updates support apps running on only Android mobile devices and tablets, and Chrome OS devices”

Android TV not mentioned, I think it’s the reason in my case.

Che
  • 156
  • 5
0

Temporary workaround for the moment is to surround the OnCompleteListener with a :

try {...} catch(e: RuntimeExecutionException) {...}

Just to avoid having to clear the PlayStore cache everytime I relaunch the app

Nicolas Ducom
  • 238
  • 2
  • 13
  • 2
    Maybe you could do this in **addOnFailureListener**? Because this is called on an error. I have the InAppUpdate process in a BaseActivity and use an interface to give back the result to any Activity who needs it. – Sceada Mar 18 '20 at 07:20
0

After long time of debugging. I found, this is because of we are testing the app directly in mobile. Even though we generate and use signed apk, this error will occur. The only way to get rid of this error is, we need to download the app from google play.

We can use Internal app sharing to test or simply publish our app.

Vimal
  • 197
  • 1
  • 11
0

Well, in my case we've cleared Google Play app cache and we didn't launch the Google Play before our app. You have to do it to download fresh data from the store, which is necessary for the SDK.

jczerski
  • 265
  • 2
  • 13