codepush更新的appVersion不正确。它始终与当前应用的版本相同

时间:2018-10-07 04:58:46

标签: android react-native code-push react-native-code-push

我正在尝试让Codepush在Android上的本机应用程序中工作。为了更好地理解和控制,我正在手动检查更新。这是我的代码:

// 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,
            });
        }
    });

要发布新更新,请按以下方式更新android / app / build.gradle文件:

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion

    defaultConfig {
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 8
        versionName "2.2.6"

appcenter codepush release-react -a <appname> -t ">=2.0.0 <=2.2.9" -d Production --description 'Trying to get codepush working'

在logcat中,我可以看到它正在获取更新,但是,更新的appVersion与从playstore安装的应用相同。在codepush上尝试过多个版本,标签会递增,但appVersion不会。

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

我的理解是否不正确,appVersion应该是build.gradle文件中更新的应用版本?

0 个答案:

没有答案