Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Invalid Version:null when versionCode is over 1000 #176

Open
timokauppinen opened this issue Mar 14, 2024 · 4 comments
Open

TypeError: Invalid Version:null when versionCode is over 1000 #176

timokauppinen opened this issue Mar 14, 2024 · 4 comments

Comments

@timokauppinen
Copy link

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.

@SudoPlz
Copy link
Owner

SudoPlz commented Mar 14, 2024

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.

@timokauppinen
Copy link
Author

timokauppinen commented Mar 17, 2024

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?

@LukasMod
Copy link

LukasMod commented Jun 6, 2024

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

@timokauppinen
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants