sp-react-native-in-app-updates icon indicating copy to clipboard operation
sp-react-native-in-app-updates copied to clipboard

TypeError: Invalid Version:null when versionCode is over 1000

Open timokauppinen opened this issue 1 year ago • 4 comments

Hello, My app latest versionCode is 1010 and sp-react-native-in-app-updates works well when versionCode is 998 (or any other number under 1000). When I install app with versionCode 1000 then it will give error "sp-react-native-in-ap-updates checkNeedsUpdate error: TypeError: Invalid Version: null"

I have been testing this with internal app sharing and the update will consistently depend less of target app versionCode -as long as there is update available. As long as installed versionCode is higher than 1000, for example 3000 and target versionCode is 4000 it will give this error.

timokauppinen avatar Mar 14 '24 13:03 timokauppinen

If I were you I'd experiment with implementing both toSemverConverter (to check the incoming version and make sure it looks like a valid semver, as well as customVersionComparator afterwards to check the versions that we compare (existing version vs remote version) in an attempt to troubleshoot what may be wrong.

Let's start there.

SudoPlz avatar Mar 14 '24 14:03 SudoPlz

OK, I did some testing as you suggersted. Here is my code just for testing

const checkForUpdate = async (appVersion: string, androidUpdateType = AndroidUpdateType.FLEXIBLE) => { return inAppUpdates.checkNeedsUpdate({ //curVersion: appVersion, toSemverConverter: (v) =>{ console.log('APPUPDATER:: got version from backend: ' + v); window.alert('APPUPDATER:: got version from backend: ' + v); return v; }, customVersionComparator: (v1, v2) => { console.log('APPUPDATER:: version comparator v1: "' + v1+'" v2: "' + v2 + '"'); window.alert('APPUPDATER:: version comparator v1: "' + v1+'" v2: "' + v2 + '"'); return v1+'' !== v2+''; } }).then((result) => { if (result.shouldUpdate) { let updateOptions: StartUpdateOptions = {}; if (Platform.OS === 'android') { // android only, on iOS the user will be promped to go to your app store page updateOptions = { updateType: androidUpdateType, }; } inAppUpdates.startUpdate(updateOptions); // https://github.com/SudoPlz/sp-react-native-in-app-updates/blob/master/src/types.ts#L78 }else{ window.alert('No newer update available'); } }).catch((error) => { window.alert(appVersion + ' Error trying to update: ' + error.message); console.recordError(error); }); }`

As you can see I am not giving app version for the library and let it handle it. What it will show in alert shows that it's trying to compare two different things: versionCode and versionName and that breaks the default comparator. image

Store will return versionCode and client is using versionName for comparison. I was also earlier following guides and giving it DeviceInfo.getVersion() which seems to be the wrong info to give to the comparator.

After I manually give Android Build number (with DeviceInfo.getBuildNumber()) I can see that it's at least trying to compare the same thing.

image

How have others not ran into this problem?

timokauppinen avatar Mar 17 '24 10:03 timokauppinen

@timokauppinen Is using customVersionComparator fix the issue with codeVersion over 1000? Our app is like 810 so we still have some time 😄

LukasMod avatar Jun 06 '24 08:06 LukasMod

I stopped testing after I got it working correctly by using build number comparison instead, I have customVersionComparator. Maybe it's something to do with "semver" library used, but anyway I still think it's comparing wrong things as in default it's comparing RNDeviceInfo.appVersion and versionCode (build number) it gets from backend, those are not same thing.

timokauppinen avatar Jun 06 '24 10:06 timokauppinen