问题描述
我正在更新应用程序的应用程序中使用应用程序内更新API
,而新版本已在Play商店中提供。
I am using In-App Update API
in the application for Update Application while the new version is available in play store.
模块gradle
defaultConfig {
applicationId "xxx.xxxxx"
minSdkVersion 21
targetSdkVersion 28
versionCode rootProject.ext.vCode
versionName rootProject.ext.vName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
最近上传的版本(Live in Playstore)
vCode = 5
vName = "1.0.4"
项目gradle(降级以进行测试)
vCode = 4
vName = "1.0.3"
降级此版本
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()
}
}
}
我上次在Play商店中使用App Bundle(.aab)和Open Beta上传了构建版本。
尝试以下方式。
- 使用相同的软件包名称签名apk。
- 清除Playstore apk缓存和存储。
- 从playstore下载apk并将其从设备上卸载。然后,在降级版本代码后,签名apk并将其安装在设备中。仍然没有显示更新应用程序对话框。
推荐答案
与其他回答相反,这些回答说测试版本必须处于发布模式或必须上传到Play Console测试轨道-完全错误,文档中没有任何提及。
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.
如果符合API> = 21&&拥有互联网连接并遇到此问题,请执行以下操作来解决:
If you meet requirements API >= 21 && have internet connection and face this issue, do the following to resolve:
- 确认您的测试版本的版本代码低于生产版本的版本代码
- 清除存储&缓存PlayStore应用
- 使用先前已下载该应用的帐户打开游戏商店
- 在PlayStore中导航至您的应用列表,并确认更新
- 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.
似乎是PlayStore的缓存问题,上述步骤可以刷新它。之后,即使在调试模式下,您也可以测试In App Updates。
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.
这篇关于在App Update API中,始终返回1(UPDATE_NOT_AVAILABLE)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!