React-native-navigation: react-native run-android failing

Created on 11 Jan 2018  路  13Comments  路  Source: wix/react-native-navigation

Issue Description

after adding the RRN package I can no longer build for Android. I've followed the steps in the Documentation but I', getting the following:

/MainActivity.java:22: error: method does not override or implement a method from a supertype
    @Override
error: MainApplication is not abstract and does not override abstract method createAdditionalReactPackages() in NavigationApplication
public class MainApplication extends NavigationApplication {
       ^
/MainApplication.java:48: error: cannot find symbol
            new NavigationReactPackage(),
                ^
  symbol: class NavigationReactPackage

Steps to Reproduce / Code Snippets / Screenshots

MainApplication.java:

import android.app.Application;

import com.facebook.react.ReactApplication;
// import com.reactnativenavigation.NavigationReactPackage;
import com.facebook.reactnative.androidsdk.FBSDKPackage;
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;
import com.facebook.CallbackManager;
import com.facebook.FacebookSdk;
import com.facebook.reactnative.androidsdk.FBSDKPackage;
import com.facebook.appevents.AppEventsLogger;

import com.reactnativenavigation.NavigationApplication;

// public class MainApplication extends Application implements ReactApplication {

public class MainApplication extends NavigationApplication {

  private static CallbackManager mCallbackManager = CallbackManager.Factory.create();

  protected static CallbackManager getCallbackManager() {
    return mCallbackManager;
  }

  @Override
  public boolean isDebug() {
      // Make sure you are using BuildConfig from your own application
      return BuildConfig.DEBUG;
  }

  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
    @Override
    public boolean getUseDeveloperSupport() {
      return BuildConfig.DEBUG;
    }

    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
            new NavigationReactPackage(),
            new FBSDKPackage(mCallbackManager)
      );
    }
  };

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

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

  @Override
  public void onCreate() {
    super.onCreate();
    FacebookSdk.sdkInitialize(getApplicationContext());
    // If you want to use AppEventsLogger to log events.
    AppEventsLogger.activateApp(this);
  }
}

Environment

  • React Native Navigation version: 1.1.335
  • React Native version:
    react-native-cli: 2.0.1
    react-native: 0.47.1
  • Platform(s) (iOS, Android, or both?): issue is in Android
  • Device info (Simulator/Device? OS version? Debug/Release?): Developing OS is macOS. The failure is independent of the android simulator

All 13 comments

@cjdcordeiro did you see this issue https://github.com/wix/react-native-navigation/issues/1484 ? please add MainActivity.java.

I just had the same problem.
I your "MainApplication.java" change the following import
import com.reactnativenavigation.NavigationReactPackage;
for
import com.reactnativenavigation.bridge.NavigationReactPackage;

Hope this help!

@DinDents thanks. That made the 3rd error disappear but the others are still there.

@dbyilmaz yes I have. Reducing my MainApplication according to that ticket:

public class MainApplication extends NavigationApplication {

  private static CallbackManager mCallbackManager = CallbackManager.Factory.create();

  protected static CallbackManager getCallbackManager() {
    return mCallbackManager;
  }

  @Override
  public boolean isDebug() {
    // Make sure you are using BuildConfig from your own application
    return BuildConfig.DEBUG;
  }

  @Override
  protected List<ReactPackage> getPackages() {
    return Arrays.<ReactPackage>asList(
        new MainReactPackage(),
          // new NavigationReactPackage(),
          new FBSDKPackage(mCallbackManager)
    );
  }

  @Override
  public List<ReactPackage> createAdditionalReactPackages() {
    return getPackages();
  }

  @Override
  public void onCreate() {
    super.onCreate();
    FacebookSdk.sdkInitialize(getApplicationContext());
    // If you want to use AppEventsLogger to log events.
    AppEventsLogger.activateApp(this);
  }
}

and the MainActivity:

import com.facebook.react.ReactActivity;
import android.content.Intent;
import com.reactnativenavigation.controllers.SplashActivity;

public class MainActivity extends SplashActivity {

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        MainApplication.getCallbackManager().onActivityResult(requestCode, resultCode, data);
    }

    /**
     * Returns the name of the main component registered from JavaScript.
     * This is used to schedule rendering of the component.
     */
    @Override
    protected String getMainComponentName() {
        return "myproject";
    }
}

The errors are:

java:22: error: method does not override or implement a method from a supertype
@Override

(on line 44 as well)

Some extra info: there's also a warning about

MainApplication.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

I think your MainApplication declaration should looks like this :
public class MainApplication extends Application implements ReactApplication

And MainActivity should extend ReactActivity
public class MainActivity extends ReactActivity

@DinDents that's what I had before installing RNN, but then I've followed the installation steps in the docs.

If I roll back to your changes, still get:

error: MainApplication is not abstract and does not override abstract method getReactNativeHost() in ReactApplication
public class MainApplication extends Application implements ReactApplication {

in addition to the others from before

@cjdcordeiro can you update react-native : ^0.49.5? try this.

@dbyilmaz thanks for the hint. But still fails the same. full error chunk:

:app:compileDebugJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.).
/Users/cristovaocordeiro/Documents/Personal/myproject/android/app/src/main/java/com/myproject/MainApplication.java:22: error: MainApplication is not abstract and does not override abstract method getReactNativeHost() in ReactApplication
public class MainApplication extends Application implements ReactApplication {
       ^
/Users/cristovaocordeiro/Documents/Personal/myproject/android/app/src/main/java/com/myproject/MainApplication.java:32: error: method does not override or implement a method from a supertype
  @Override
  ^
/Users/cristovaocordeiro/Documents/Personal/myproject/android/app/src/main/java/com/myproject/MainApplication.java:44: error: method does not override or implement a method from a supertype
  @Override
  ^
/Users/cristovaocordeiro/Documents/Personal/myproject/android/app/src/main/java/com/myproject/MainApplication.java:59: error: method does not override or implement a method from a supertype
  @Override
  ^
Note: /Users/cristovaocordeiro/Documents/Personal/myproject/android/app/src/main/java/com/myproject/MainApplication.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
4 errors
:app:compileDebugJavaWithJavac FAILED

Here is my MainApplicationClass, maybe it can help you :

public class MainApplication extends Application implements ReactApplication {  
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
    @Override
    public boolean getUseDeveloperSupport() {
      return BuildConfig.DEBUG;
    }
    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          // My Packages
      );
    }
  };
  @Override
  public ReactNativeHost getReactNativeHost() {
    return mReactNativeHost;
  }

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

Another thing you check is you build.gradle (App).
In android make sure your compileSdkVersion is 26
And in dependencies check that you use the latest version of android compiler something like

dependencies {
    //noinspection GradleCompatible,GradleCompatible
    compile 'com.android.support:appcompat-v7:26.1.0'
    //    compile "com.android.support:appcompat-v7:23.0.1"
    compile 'com.facebook.react:react-native:+'
    // From node_modules
}

@DinDents I've just upgraded to sdk 26 (was working with 25). But the result is the same.

If I remove all the @Override from both Main*.java, it compiles, but then fails to launch the application in the simulator. I'm not sure if the error is related though or whether it is safe to remove the Override...

This warning is caused by a @providesModule declaration with the same name across two different files.
Bundling `index.android.js`  [development, non-minified, hmr disabled]  100.0% (398/398), failed.
Error: ENOENT: no such file or directory, open '/Users/cristovaocordeiro/Documents/Personal/myproject/node_modules/metro-bundler/src/Resolver/polyfills/prelude_dev.js'
    at Object.fs.openSync (fs.js:651:18)
    at Object.fs.readF

update: I've now updated everything, and I'm seeing the same as in https://github.com/wix/react-native-navigation/issues/2493

@cjdcordeiro Is there package com.projectname; in files?

I'll close this issue since is duplicate with #2493

Was this page helpful?
0 / 5 - 0 ratings