I am using In-App Update API
in the application for Update Application while the new version is available in play store.
module gradle
defaultConfig {
applicationId "xxx.xxxxx"
minSdkVersion 21
targetSdkVersion 28
versionCode rootProject.ext.vCode
versionName rootProject.ext.vName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
Last upload version(Live in Playstore)
vCode = 5
vName = "1.0.4"
project gradle (downgrade it for the testing)
vCode = 4
vName = "1.0.3"
Downgrade this version for the testing update available or not.
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()
}
}
}
I last uploaded build in play store with App Bundle(.aab) and Open Beta.
Tried following ways.
- Sign apk with the same package name.
- Clear Playstore apk cache and storage.
- Download apk from playstore and uninstall it from device. then after downgrade version code and sign apk and install it in device. Still not showing update app dialog.
Make sure:
you install Signed Release version for testing
with the same applicationId as in Play Store (your flavour doesn't have any applicationIdSuffix)
and versionCode is lower
and your app is released (as a tester you can download it)
Here is how I test my in-app update and it's confirmed working for me everytime I rollout.
I use internal test track and increment version code.
use Google play store to install a version of the testing app (I used internal test track rollout)
rollout another version with higher VERSION CODE on Play Console (the same internal test track)
close both testing app and Google play store (not just back to home, use recent key and swipe them off)
open the Google play store and ensure that testing app has an update available (you can check it under "My Apps & Game" > Installed)
now open the testing app and check for UPDATE_AVAILABLE
This works for me almost immediately after rollout
Android In-App Update Api showing UPDATE_NOT_AVAILABLE
What is helping me during testing is opening Google play store app and open "My apps & games" position from drawer menu.
Make sure on "Updates" tab your tested application appears in "Updates Pending".
That library in my opinion does not check on some google api is there any update available, but is checking some kind of google play store app cache
hope it helps cheers Wojtek
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.
If you meet requirements API >= 21 && have internet connection and face this issue, do the following to resolve:
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.