重新启动后反应本机代码推送回滚

React Native codePush rollback after restart

我正在尝试实施AppCenter CodePush来更新Javascript代码,而不必经过App Store审查过程。

我已经按照此处提到的iOS和Android步骤来设置多部署环境:
https://github.com/microsoft/react-native-code-push/blob/master/docs/multi-deployment-testing-ios.md
https://github.com/microsoft/react-native-code-push/blob/master/docs/multi-deployment-testing-android.md

版本

"react-native":"0.59.10"

"react-native-code-push":"^5.6.1"

我在使用react-native run-android --variant release的Android上进行了尝试,在iOS上,我将RUN和Archive方案更改为STAGING。但是在这两种情况下,它们似乎都是像[CodePush] Loading JS bundle from"assets://index.android.bundle"这样来获取我的捆绑包,而不是从CodePush存储库中获取。这是我看到的唯一输出(与CodePush相关)。

我做了一个codePush版本,如下所示:appcenter codepush release-react -a name/appName-1 -d Staging。此命令成功执行,我在具有正确版本的iOS和Android登台环境中看到它。

componentDidMount

1
2
3
4
5
6
7
8
componentDidMount() {
    codePush.notifyApplicationReady();
    ...
    codePush.sync({
      updateDialog: true,
      installMode: codePush.InstallMode.IMMEDIATE
    });
  }

导出应用程序

1
2
3
4
5
App = codePush({
  checkFrequency: codePush.CheckFrequency.ON_APP_RESUME
})(App);

AppRegistry.registerComponent("myApp", () => App);

Info.plist

CodePushDeploymentKey: $(CODEPUSH_KEY)

android / app / build.gradle

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
buildTypes {
        debug {
            buildConfigField"String","CODEPUSH_KEY", '""'
        }

        releaseStaging {
            buildConfigField"String","CODEPUSH_KEY", '"my_code"'
            matchingFallbacks = ['release']
        }
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"),"proguard-rules.pro"
            signingConfig signingConfigs.release
            buildConfigField"String","CODEPUSH_KEY", '"my_code"'
        }
    }

我的构建设置包含codePush Release和登台代码。

enter

1
2
3
4
5
6
7
#import <CodePush/CodePush.h>

#if DEBUG
  return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
  return [CodePush bundleURL];
#endif

MainApplication.java更改:

1
2
3
4
5
6
7
8
9
10
11
import com.microsoft.codepush.react.CodePush;
@Override
protected String getJSBundleFile() {
  return CodePush.getJSBundleFile();
}

@Override
protected List<ReactPackage> getPackages() {
  return Arrays.<ReactPackage>asList(
    ..
    new CodePush(BuildConfig.CODEPUSH_KEY, MainApplication.this, BuildConfig.DEBUG),

build.gradle更改:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
buildTypes {
  debug {
    buildConfigField"String","CODEPUSH_KEY", '""'
  }

  releaseStaging {
    buildConfigField"String","CODEPUSH_KEY", '"<staging_key>"'
    matchingFallbacks = ['release']
  }

  release {
    ..
    buildConfigField"String","CODEPUSH_KEY", '"<prod_key>"'
  }
}


您是否正在模拟器中对此进行测试?

如果是这样,执行reload基本上可以模拟CodePush眼中的崩溃。

如果您在模拟器中运行,CodePush的行为将与未绑定到打包程序的真实设备的行为有所不同。最好的测试方法是进行构建并将该构建上传到商店以分发到您的测试池。

然后,您可以通过Google Play商店或testflight for iOS下载并安装内部版本,并在此处测试您的CodePush安装。

编辑:

聊天后,对以下代码进行了更改,我们可以正常工作:

首先,创建一个options对象,并将其用于我们的codePush调用中:

1
2
3
4
5
const options = {
  updateDialog: true,
  installMode: codePush.InstallMode.IMMEDIATE,
  checkFrequency: codePush.CheckFrequency.ON_APP_RESUME
};

然后我们可以调用codePush sync,如下所示:
codePush.sync(options);

最后,我们没有将codePush设置分配给App,而是将其全部移动到了一行:

1
2
3
AppRegistry.registerComponent("myApp", () =>
  codePush(options)(App)
);

不是不是CodePush专家,我不知道是否需要选项部分,尽管我认为在不同点使用不同的选项可能会导致不一致。

我确实认为调用App = codePush(options)(App)会引起问题。

无论哪种方式,这两件事的结合都解决了该问题。


我遇到了同样的问题,所以我只是在我的应用着陆页上写下了codePush.notifyAppReady(),并确保在检查新更新之前先做了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
componentDidMount(): void {
        codePush.notifyAppReady()
        this.checkUpdate();
}

checkUpdate = async () => {
    const updateData: RemotePackage | null = await codePush.checkForUpdate()
    if (updateData && !updateData.failedInstall) {
        //your code
        this.setState({
            isMandatory: updateData.isMandatory,
            whatsNew: updateData.description,
            showAppUpdateDialog: true
        })
    }
}