Code-Push с пакетом React-Native всегда равен нулю

Мы пытаемся внедрить CodePush из Microsoft App Center. Нам удалось добраться до точки, где приложение загружает пакет и распаковывает его. Тем не менее, это всегда заканчивается ответом

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@16.2.0
  • react-native@0.53.3
  • react-native-code-push@5.3.2

Мы внесли изменения в 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.

1 ответ

Решение

Похоже, что реактивный компоновщик помещает некоторые вещи в неправильный класс

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);
}
Другие вопросы по тегам