react-native - React Native codePush 重启后回滚

标签 react-native react-navigation code-push react-native-code-push

我正在尝试实现 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"
我在 Android 上试过 react-native run-android --variant release在 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

componentDidMount() {
    codePush.notifyApplicationReady();
    ...
    codePush.sync({
      updateDialog: true,
      installMode: codePush.InstallMode.IMMEDIATE
    });
  }

导出应用
App = codePush({
  checkFrequency: codePush.CheckFrequency.ON_APP_RESUME
})(App);

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

Info.plist
CodePushDeploymentKey: $(CODEPUSH_KEY)
android/app/build.gradle
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"'
        }
    }

我的build设置包含 codePush Release 和暂存代码。

enter image description here

我还尝试将 CodePush 暂存版本升级到生产,但这并没有解决我的问题。
appcenter codepush deployment list -a Name/MyApp总是返回 0(1 挂起)。
enter image description here

更新
在批准成功更新应用程序后,它会要求更新应用程序。但是当我重新启动应用程序时,它会回滚到以前的版本。

更新 2
AppDelgate.m 更改:
#import <CodePush/CodePush.h>

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

MainApplication.java 更改:
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 更改:
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 的行为将与在未绑定(bind)到打包程序的真实设备上的行为不同。测试它的最佳方法是进行构建并将该构建上传到商店以分发到您的测试池。

然后,您可以通过 Google Play 商店或 iOS 的 testflight 下载并安装您的构建,并在那里测试您的 CodePush 安装。

编辑:

经过聊天,并进行了以下代码更改,我们得到了工作:

首先,创建一个选项对象,并在我们的 codePush 调用中使用它:

const options = { 
  updateDialog: true, 
  installMode: codePush.InstallMode.IMMEDIATE, 
  checkFrequency: codePush.CheckFrequency.ON_APP_RESUME 
}; 

然后我们可以调用codePush同步如下:codePush.sync(options);
最后,而不是将 codePush 设置分配给 App ,我们将其全部移至一行:
AppRegistry.registerComponent("myApp", () => 
  codePush(options)(App) 
);

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

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

不管怎样,这两件事的结合解决了这个问题。

关于react-native - React Native codePush 重启后回滚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57359331/

相关文章:

ios - react native iPhone X SafeAreaView

react-native - IOS模拟器应用程序留在后台

javascript - clearTimeout 在 React Native 上不起作用

reactjs - 使用 Hooks 在功能组件中 react 导航标题

react-native - 类声明中类型参数少于 1 个的组件

react-native - 如何使用代码推送 CLI 更新 "Production"部署?

javascript - React Navigation v5 如何使用 typescript 在选项卡之间导航

react-native - React Native Navigation - 使用组件状态的 Action

reactjs - 了解react-native的代码推送

ios - code-push react-native 会覆盖 iOS 版本并将旧的推送部署到新版本吗?