javiersantos / AppUpdater

A library that checks for your apps' updates on Google Play, GitHub, Amazon, F-Droid or your own server. API 9+ required.
Apache License 2.0
1.98k stars 412 forks source link

ONLY update.latestCodeVersion is returning NULL. #164

Closed mcg95 closed 5 years ago

mcg95 commented 5 years ago
Details
Builder
  private fun checkAppUpdate(){
        val appUpdaterUtils = AppUpdaterUtils(this)
            .setUpdateJSON(jsonURL)
            .withListener(object : AppUpdaterUtils.UpdateListener {
                override fun onSuccess(update: Update, isUpdateAvailable: Boolean?) {

                    Log.d("Latest Version", update.latestVersion)
                    Log.d("Latest Version Code", update.latestVersionCode.toString())
                    Log.d("Release notes", update.releaseNotes)
                    Log.d("URL", update.urlToDownload.toString())
                    Log.d("Is update available?", java.lang.Boolean.toString(isUpdateAvailable!!))
                    if (update.latestVersionCode > BuildConfig.VERSION_CODE.toString()) {
                        appUpdater = AppUpdater(this@LoginActivity)
                        appUpdater?.setCancelable(false)?.setIcon(R.drawable.hauz_security_icon_round)?.setButtonDoNotShowAgain("")?.setButtonDismiss("")?.setDisplay(Display.DIALOG)?.setUpdateJSON(jsonURL)?.start()
                    }
                }

                override fun onFailed(error: AppUpdaterError) {
                    Log.d("AppUpdater Error", "Something went wrong")
                }
            })
        appUpdaterUtils.start()
    }
Reproduction Steps
  1. Added my json file
  2. Library reads all the data in the json file correctly except the version code is always Null.
Expected Result

update.latestVersionCode = 23

Actual Result

update.latestVersionCode = Null

JSON Format: Tried { "latestVersion": "1.0.0", "latestVersionCode": 23, "url": "https://play.google.com/store/apps/details?id=com.hauz.hauzclocking", "releaseNotes": [ "- Fixed minor issues" ] }

AND

{ "latestVersion": "1.0.0", "latestVersionCode": 23, "url": "https://play.google.com/store/apps/details?id=com.hauz.hauzclocking", "releaseNotes": [ "- Fixed minor issues" ] }

Difference being latestVersionCode was changed from Int to String. Still no luck. Looked through all the older issues, none of them seemed to face an issue like this except one person. But there was no solution mentioned in the issue.

Issue: https://github.com/javiersantos/AppUpdater/issues/118

mcg95 commented 5 years ago

Managed to solve it, I forgot to include setUpdateFrom(UpdateFrom.Json) in the builder.