2

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 ?

Kira
  • 415
  • 4
  • 16
  • I worked around this issue by versioning in code myself - put `APP_VERSION = '2.2.5'` in JS code, and put the new version number in the codepush release description (`version 2.2.6 - blah`), parse the new version, validate and apply. All in all, codepush is a very nice to have feature, but needs some work and understanding to get it right. – Kira Oct 07 '18 at 08:54
  • Also, my app kept rolling back and I couldn't understand why. Read this for more info : https://github.com/Microsoft/react-native-code-push/issues/323, and call `codePush.notifyAppReady` in the beginning of the app startup to mark the release successful. Else, it gets rolled back. – Kira Oct 07 '18 at 08:58
  • Is my understanding of your is correct? You want to update the native version? I mean get the appVersion of the installed app and then change that? – Ashwin Mothilal Oct 07 '18 at 14:31
  • Yes. i thought appVersion field in the update would reflect the version of the update that was installed (and hence get updated), but doesn't seem to be the case. – Kira Oct 17 '18 at 19:21
  • No, it will just target the app version to download the code push bundle. – Ashwin Mothilal Oct 17 '18 at 19:28

0 Answers0