应用内更新给出 InstallException (ERROR_API_NOT_AVAILABLE)

Uma*_*ari 16 android in-app-update google-play-core

使用以下代码片段实现了应用内更新功能:

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();
    });
}
Run Code Online (Sandbox Code Playgroud)

我正在安装 Android 9 的设备上测试应用程序内更新。 尽管如此,它仍然给我以下错误(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)
Run Code Online (Sandbox Code Playgroud)

据说检查以下链接:https : //developer.android.com/reference/com/google/android/play/core/install/model/InstallErrorCode#ERROR_API_NOT_AVAILABLE

使用 Play 核心库版本:1.6.5

最新的核心库版本:

implementation 'com.google.android.play:core:1.7.0'
Run Code Online (Sandbox Code Playgroud)

但是,我不明白为什么说 ERROR_API_NOT_AVAILABLE。任何帮助,将不胜感激!

Vip*_*sri 12

首先,请检查您使用的是最新版本的播放库。

其次,低调的事实:请检查您正在测试的应用程序是否与 Play 商店中提供的软件包名称相同。

例子:

您在 Play 商店中有一个带有包名称com.example.app的应用程序,但您正在使用包名称测试您的应用程序com.example.app.debug。您将收到此错误:ERROR_API_NOT_AVAILABLE

注意:当您进行测试时,您需要在 Play 商店中至少拥有一个版本的应用程序。


小智 8

除了 Vipal 的建议之外,该问题可能是由于您在设备上安装的版本与 Play 商店将提供的版本之间的签名不匹配(如果您尝试使用调试版本对其进行测试,这是一个常见问题)。请参阅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


Abd*_*een 2

我的应用程序在今天之前运行良好,但今天开始出现此错误。一种临时解决方法是清除 Google Play 商店缓存和存储,然后尝试启动应用程序。对我来说,它只在第一次有效,但之后就会失败。在再次启动应用程序之前,我必须再次清除缓存和存储。我认为 Google Play 商店方面出现问题,导致此问题发生,因为在今天之前我一切都很好。