SudoPlz / sp-react-native-in-app-updates

An in-app updater for the native version of your react-native app.
MIT License
459 stars 65 forks source link

not working correctly for android ( getting version code instead of version name) #100

Open Udit-takkar opened 2 years ago

Udit-takkar commented 2 years ago

On ios is it working fine but in android it is always returning shouldUpdate even though it is updated. the store version is returning versionCode instead of version.

phone:- OnePlus7 sp-react-native-in-app-updates: 1.1.7 "react-native": "0.64.0"

xtl-geiger commented 2 years ago

I am experiencing a similar problem. Using 1.1.6.

In this line the dependency ends up comparing the buildNumber with the versionName. (f.e. 510 with 0.8.1) https://github.com/SudoPlz/sp-react-native-in-app-updates/blob/ed1080b6ab379dacd44d550933ad3a8937ca78af/src/InAppUpdates.android.ts#L119

android-update-bug

The number and the string seen in UPDATE DEBUG: 10605 0.9.4 are the parameters newAppV, appVersion the customComparator is getting.

@SudoPlz Did something change here on Google's or react-native-device-info's side?

ddikodroid commented 2 years ago

@Udit-takkar @xtl-geiger did you guys manage to solve it?

Udit-takkar commented 2 years ago

Nope

kriss-u commented 1 year ago

I am using the latest version. I am not even getting the Store version. I am not sure what went wrong.

xtl-geiger commented 1 year ago

@Udit-takkar @xtl-geiger did you guys manage to solve it?

Yes I ended up using the buildNumber from DeviceInfo and comparing it using a customVersionComparator.

alee0510 commented 1 year ago

@Udit-takkar @xtl-geiger did you guys manage to solve it?

Yes I ended up using the buildNumber from DeviceInfo and comparing it using a customVersionComparator.

I had the same issue, can you give me your code snippet on how to implement customVersionComparator? @xtl-geiger

manjuy124 commented 1 year ago

Anyone able to fix this/found a workaround? Also Is this issue with repo or google?

luckydunia054 commented 1 year ago

Hi @xtl-geiger can you provide more details that how have you resolved it?

demipixel commented 1 year ago

So nobody else has to spend 2 hours solving this

inAppUpdates
      .checkNeedsUpdate({
        // Bug with library, as it tries to compare
        // build number (on store) and version (on device)
        // So, we manually pass in build number
        curVersion: Platform.OS === 'android' ? curBuildNumber : undefined,
        customVersionComparator:
          Platform.OS === 'android'
            ? (v1, v2) => {
                return v1 > v2 ? 1 : v1 < v2 ? -1 : 0;
              }
            : undefined,
      })
pedrodlz commented 1 year ago

It is not possible to obtain store version number instead of build number?

leabaertschi commented 1 year ago

Same here, I absolutely need the store version number since we only want to compare the major part of the SemVer version. Is there a way to do that?

xtl-geiger commented 1 year ago

@pedrodlz @leabaertschi I doubt it is possible using this dependency at the moment, seeing as it uses Android's AppUpdateInfo under the hood:

https://github.com/SudoPlz/sp-react-native-in-app-updates/blob/master/android/src/main/java/com/sudoplz/rninappupdates/SpReactNativeInAppUpdatesModule.java#L91

And AppUpdateInfo only provides these values:

https://developer.android.com/reference/com/google/android/play/core/appupdate/AppUpdateInfo.html

Seeing as availableVersionCode simply returns the Integer version code of your app build number and AppUpdateInfo does not have a method to retrieve the store version of your app you would need to use a different approach to get the app version from the play store and compare it.

You could either query the play store for the version yourself or use a dependency to get the store version.

F.e. https://github.com/watanabeyu/react-native-store-version
https://github.com/kimxogus/react-native-version-check
etc.

JJSLIoT commented 1 year ago

@leabaertschi You can use react-native-store-version to check the semantic version of the app on the App/Play store and then compare it with the installed app version.

pedrodlz commented 1 year ago

@pedrodlz @leabaertschi I doubt it is possible using this dependency at the moment, seeing as it uses Android's AppUpdateInfo under the hood:

https://github.com/SudoPlz/sp-react-native-in-app-updates/blob/master/android/src/main/java/com/sudoplz/rninappupdates/SpReactNativeInAppUpdatesModule.java#L91

And AppUpdateInfo only provides these values:

https://developer.android.com/reference/com/google/android/play/core/appupdate/AppUpdateInfo.html

Seeing as availableVersionCode simply returns the Integer version code of your app build number and AppUpdateInfo does not have a method to retrieve the store version of your app you would need to use a different approach to get the app version from the play store and compare it.

You could either query the play store for the version yourself or use a dependency to get the store version.

F.e. https://github.com/watanabeyu/react-native-store-version https://github.com/kimxogus/react-native-version-check etc.

I have moved to https://github.com/kimxogus/react-native-version-check and works perfectly fine.

leabaertschi commented 1 year ago

Thanks everyone, I'll have a look at the proposed modules.