I am trying to get codepush working for my react-native app on Android. For better understanding and control, i am manually checking for updates. Here's my code:
// Check for Codepush app update every time app is opened.
console.log('Checking for codepush update !');
codePush.checkForUpdate(CODEPUSH_DEPLOYMENT_KEY, (update) => {console.log('handleBinaryVersionMismatchCallback: ', update)})
.then((update) => {
console.log('Code push remote package: ', update);
if (update != null) {
let desc = update['description'];
let newVersion = update['appVersion'];
let currentVersion = RNDeviceInfo.getVersion();
console.log('current version: ', currentVersion);
let currentSemVer = currentVersion.split('.');
let newSemVersion = newVersion.split('.');
let curV = parseFloat(currentSemVer[1] + '.' + currentSemVer[2]);
let newV = parseFloat(newSemVersion[1] + '.' + newSemVersion[2]);
console.log('currentSemVer:', currentSemVer);
console.log('newSemVersion:', newSemVersion);
console.log('curV:', curV);
console.log('newV:', newV);
if (currentVersion === newVersion) {
console.log('Exact same version. Ignoring codepush');
return;
}
if (newSemVersion[0] !== currentSemVer[0]) {
console.log('Major version mismatch. Ignoring codepush');
return;
}
if (newV < curV) {
console.log('Older version. Ignoring codepush');
return;
}
codePush.sync({
updateDialog: true,
installMode: codePush.InstallMode.IMMEDIATE,
});
}
});
To release a new update, i update the android/app/build.gradle file like this:
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 8
versionName "2.2.6"
and
appcenter codepush release-react -a <appname> -t ">=2.0.0 <=2.2.9" -d Production --description 'Trying to get codepush working'
In logcat, i can see that its getting the update, however, the appVersion of the update is the same as the app that was installed from playstore. Have tried multiple releases on codepush, the label increments, but the appVersion does not.
10-07 10:14:51.798 7668-7701/? I/ReactNativeJS: 'Code push remote package: ', { deploymentKey: '<key>',
description: 'Trying to get codepush working',
label: 'v8',
appVersion: '2.2.5',
isMandatory: false,
packageHash: '<>',
packageSize: 616685,
downloadUrl: '<>',
download: [Function],
isPending: false,
failedInstall: false }
'current version: ', '2.2.5'
'currentSemVer:', [ '2', '2', '5' ]
'newSemVersion:', [ '2', '2', '5' ]
10-07 10:14:51.799 7668-7701/? I/ReactNativeJS: 'curV:', 2.5
'newV:', 2.5
Exact same version. Ignoring codepush
Is my understanding incorrect that appVersion should be the update's app version from the build.gradle file ?