使用 React-Native 捆绑包的代码推送始终为空

Code-Push with React-Native bundle is always null

我们正在尝试从 Microsoft App Center 实施 CodePush。我们已经设法到达应用程序下载包并将其解包的地步。但是,它总是以 response

结束

Update is invalid - A JS bundle file named "null" could not be found within the downloaded contents. Please check that you are releasing your CodePush updates using the exact same JS bundle file name that was shipped with your app's binary.

我们对 MainApplication.java

进行了更改
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {

  @NonNull
    @Override
    protected String getJSBundleFile() {
    return CodePush.getJSBundleFile();
    }

protected List<ReactPackage> getPackages() {
   return Arrays.<ReactPackage>asList(
   // Add additional packages you require here
   // No need to add RnnPackage and MainReactPackage
   new ActionSheetPackage(),
   new PickerPackage(),
   new ReactNativeOneSignalPackage(),
   new CodePush(getResources().getString(R.string.reactNativeCodePush_androidDeploymentKey), getApplicationContext(), BuildConfig.DEBUG),
   new CalendarEventsPackage()
 );
}

在应用程序代码中,我们调用

 Navigation.registerComponent(ScreenNames.Landing.id, () => CodePush(codePushOptions)(LandingScreen), store, Provider);

代码推送调试的最终日志android

[11:31:37] Awaiting user action.
[11:31:42] Downloading package.
[11:31:43] An unknown error occurred.
[11:31:43] Update is invalid - A JS bundle file named "null" could not be found within the downloaded contents. Please check that you are releasing your CodePush updates using the exact same JS bundle file name that was shipped with your app's binary.

看来 react-native 链接器把某些东西放错了 class

public class MainApplication extends NavigationApplication {


private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this)     
{
  @NonNull
  @Override
  public String getJSBundleFile() {
    return CodePush.getJSBundleFile();
  }

覆盖应该在 MainApplication 上,而不是 ReactNativeHost

public class MainApplication extends NavigationApplication {

  @NonNull
  @Override
  public String getJSBundleFile() {
    return CodePush.getJSBundleFile();
  }

private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this)            
{ /*... */ }

您必须在 ReactGateway createReactGateway(){} 方法中 覆盖 它。

这对我有用。

@Override
protected ReactGateway createReactGateway() {
    ReactNativeHost host = new NavigationReactNativeHost(this, isDebug(), createAdditionalReactPackages()) {
        @Override
        protected String getJSMainModuleName() {
            return "index";
        }

        @NonNull
        @Override
        public String getJSBundleFile() {
            return CodePush.getJSBundleFile();
        }
    };
    return new ReactGateway(this, isDebug(), host);
}