android - 为什么 Android 应用内更新总是返回 UPDATE_NOT_AVAILABLE 并且版本代码为 0?
问题描述
我正在使用这些说明从 Android Studio 测试应用内更新。
为了测试,我删除了我的应用程序并在 gradle 中设置了一个次要版本代码,然后我将这个版本的应用程序从调试安装到我的设备中。
上面的代码总是返回UPDATE_NOT_AVAILABLE
。
代码:
private void checkForUpdates() {
// Creates instance of the manager.
AppUpdateManager appUpdateManager = AppUpdateManagerFactory.create(MainActivity.this);
// Returns an intent object that you use to check for an update.
Task<AppUpdateInfo> appUpdateInfoTask = appUpdateManager.getAppUpdateInfo();
// Checks that the platform will allow the specified type of update.
Log.d(TAG, "upd_1:" + appUpdateManager.getAppUpdateInfo());
appUpdateInfoTask.addOnSuccessListener(appUpdateInfo -> {
Log.d(TAG, "upd_2:" + appUpdateInfo.updateAvailability());
Log.d(TAG, "upd_3:" + appUpdateInfo.availableVersionCode());
if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE
// For a flexible update, use AppUpdateType.FLEXIBLE
&& appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)) {
// Request the update.
try {
appUpdateManager.startUpdateFlowForResult(
// Pass the intent that is returned by 'getAppUpdateInfo()'.
appUpdateInfo,
// Or 'AppUpdateType.FLEXIBLE' for flexible updates.
AppUpdateType.IMMEDIATE,
// The current activity making the update request.
this,
// Include a request code to later monitor this update request.
MY_REQUEST_CODE);
} catch (IntentSender.SendIntentException e) {
e.printStackTrace();
}
}
});
}
这是我的日志:
这是日志updateAvailability()
:
2019-12-05 17:00:39.436 3381-3381/org.my.app D/MainActivity: upd_2:1
这是日志availableVersionCode()
:
2019-12-05 17:00:39.436 3381-3381/org.my.app D/MainActivity: upd_3:0
我如何测试更新应用内 previos 以上传我的这个应用的新版本?
解决方案
在这里聚会有点晚了,但希望这可以帮助将来的其他人:
您收到错误响应的原因是您尝试提供更新的新 APK 和您当前安装的 APK 必须由您的生产密钥(也称为发布版本)签名。使用调试版本将导致此调用每次都失败。
为了正确测试这一点,我建议将发布的 APK 上传到 Google Developer Console 上的内部测试轨道。像这样的东西:
- 将版本上传
x.x.1
到内部测试轨道,并使用链接下载到您的设备 - 将碰撞版本上传
x.x.2
到内部测试轨道 - 在 Play 商店中导航到您的应用(应显示可用更新)
- 进入您的应用程序并测试您期望的用户流
推荐阅读
- python - 在 python 中导入 sklearn 时出错 - ImportError
- python - 如何逐字反转Python中的字符串?
- linux - 使用 GREP 在整个外显子组制表符分隔的文本文件中查找基因列表(大约 200 个)
- c# - 将 CosmosDB 提供程序用于 Entity Framework Core 和 Azure 表时出错
- javascript - 为什么firebase不部署放置在公共目录之外的文件?
- android - Android WorkManager PeriodicWorkRequest 执行问题
- java - java.lang.NoSuchMethodError:org.springframework.util.ReflectionUtils.accessibleConstructor
- docker - HaProxy 转发代理在 HTTP 上工作,但在 HTTPS 上给出 503
- android-studio - 如何在 Flutter 中仅为 OutlineButton 制作带下划线的边框
- laravel - 我如何修复 Illuminate\Database\Eloquent\Collection 类的错误对象无法转换为 int