react-native-navigation icon indicating copy to clipboard operation
react-native-navigation copied to clipboard

Code Push implementation Error with RNN: MainApplication cannot override getJSBundleFile()

Open larryranches opened this issue 9 years ago • 13 comments

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

larryranches avatar Jul 13 '17 20:07 larryranches

+1

dorthwein avatar Jul 25 '17 16:07 dorthwein

~~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 avatar Jul 30 '17 09:07 pewh

@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.

felipemartim avatar Sep 18 '17 22:09 felipemartim

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);
  }
}

pewh avatar Sep 19 '17 03:09 pewh

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

pewh avatar Sep 19 '17 04:09 pewh

anyone know how this would work on RNN v1?

ericlewis avatar Nov 10 '17 23:11 ericlewis

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.

zhangandroid avatar Dec 20 '17 08:12 zhangandroid

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.

stale[bot] avatar Jun 02 '18 09:06 stale[bot]

The issue has been closed for inactivity.

stale[bot] avatar Jun 09 '18 09:06 stale[bot]

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);
        }

esipavicius avatar Oct 02 '18 22:10 esipavicius

thank you, @esipavicius, works like a charm.

seavan avatar Feb 20 '20 09:02 seavan

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

kanso-michael avatar Jun 19 '20 13:06 kanso-michael

@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;
    }
}

seavan avatar Jun 21 '20 07:06 seavan