React-native-navigation: Code Push implementation Error with RNN: MainApplication cannot override getJSBundleFile()

Created on 13 Jul 2017  路  13Comments  路  Source: wix/react-native-navigation

I'm trying to implement code push to my project using this react-native-navigation. I need to run the code below to have code push make updates. I am receiving this error: MainApplication cannot override getJSBundleFile() in NavigationApplication. This is happening with building for Android. Is there a way to override this method as it's necessary for code push implementation? Help would be very nice.

// 2. Override the getJSBundleFile method in order to let
// the CodePush runtime determine where to get the JS
// bundle location from on each app start
        @Override
        protected String getJSBundleFile() {
            return CodePush.getJSBundleFile();
        }

Environment

  • React Native Navigation version: 2.0.0-experimental.302
  • React Native version: 0.45.1
  • Platform(s) (iOS, Android, or both?): Android
  • Device info (Simulator/Device? OS version? Debug/Release?): Debug and release, nexus 7
馃彋 stale

Most helpful comment

+1

All 13 comments

+1

Just replace protected with public. Hope it helps.

EDIT:
Just follow https://github.com/wix/react-native-navigation/issues/884#issuecomment-287652837 & it's working now.

@pewh do you have a working source code for MainApplication.java with code push enabled? I couldn't make it work by following the comment you linked.

package com.example;

import android.app.Application;
import com.facebook.react.ReactApplication;
import com.microsoft.codepush.react.CodePush;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;

import java.util.Arrays;
import java.util.List;

public class MainApplication extends Application implements ReactApplication {

  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {

    @Override
    public boolean getUseDeveloperSupport() {
      return BuildConfig.DEBUG;
    }

    // from react-natice-code-push
    @Override
    protected String getJSBundleFile() {
      return CodePush.getJSBundleFile();
    }

    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
        new MainReactPackage(),
        new CodePush(BuildConfig.CODEPUSH_KEY, getApplicationContext(), BuildConfig.DEBUG),
      );
    }
  };

  @Override
  public ReactNativeHost getReactNativeHost() {
    return mReactNativeHost;
  }

  @Override
  public void onCreate() {
    super.onCreate();
    SoLoader.init(this, /* native exopackage */ false);
  }
}

What RN version do you use? Mine is testing with RN 0.47 & 0.48

anyone know how this would work on RNN v1?

public class MainApplication extends NavigationApplication {
@Override
public String getJSBundleFile() {
return CodePush.getJSBundleFile();
}
@Override
public boolean isDebug() {
return BuildConfig.DEBUG;
}
@Override
public List createAdditionalReactPackages() {
return Arrays.asList(
......
new CodePush("deploymentKey" , getApplicationContext(), BuildConfig.DEBUG)
);
}
@Override
public void onCreate() {
super.onCreate();

}

}

override getJSBundleFile instead of the react-native-code-push config.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you believe the issue is still relevant, please test on the latest version and report back. Thank you for your contributions.

The issue has been closed for inactivity.

I found where it should be in navigation v2:

        @Override
        protected ReactGateway createReactGateway() {
            ReactNativeHost host = new NavigationReactNativeHost(this, isDebug(), createAdditionalReactPackages()) {
                protected String getJSBundleFile() {
                    return CodePush.getJSBundleFile();
                }

                @Override
                protected String getJSMainModuleName() {
                    return "index";
                }
            };
            return new ReactGateway(this, isDebug(), host);
        }

thank you, @esipavicius, works like a charm.

@seavan Can you share your working MainApplication.java setup?

@seavan Can you share your working MainApplication.java setup?

public class MainApplication extends NavigationApplication {
    private final ReactModuleRegistryProvider mModuleRegistryProvider = new ReactModuleRegistryProvider(new BasePackageList().getPackageList(), null);

    private final ReactNativeHost mReactNativeHost =
            new NavigationReactNativeHost(this) {
                @Override
                protected String getJSMainModuleName() {
                    return "index";
                }

                @Override
                public boolean getUseDeveloperSupport() {
                    return BuildConfig.DEBUG;
                }

                protected String getJSBundleFile() {
                    return CodePush.getJSBundleFile();
                }

                @Override
                public List<ReactPackage> getPackages() {
                    @SuppressWarnings("UnnecessaryLocalVariable")
                    List<ReactPackage> packages = new PackageList(this).getPackages();
                    // Packages that cannot be autolinked yet can be added manually here, for example:
                    // packages.add(new MyReactNativePackage());

                    // Add unimodules
                    List<ReactPackage> unimodules = Arrays.<ReactPackage>asList(
                            new ModuleRegistryAdapter(mModuleRegistryProvider)
                    );
                    packages.addAll(unimodules);

                    return packages;
                }
            };

    @Override
    public ReactNativeHost getReactNativeHost() {
        return mReactNativeHost;
    }
}
Was this page helpful?
0 / 5 - 0 ratings