11

Hi after importing my react native project expo and upgrading react, I've been have the following problems.

C:\Users\user\gramic\android\app\src\main\java\com\shop\MainApplication.java:5: error: cannot find symbol import com.facebook.react.ReactApplication; ^ symbol: class ReactApplication location: package com.facebook.react C:\Users\user\gramic\android\app\src\main\java\com\shop\MainApplication.java:13: error: cannot find symbol import com.facebook.react.ReactNativeHost; ^ symbol: class ReactNativeHost location: package com.facebook.react C:\Users\user\gramic\android\app\src\main\java\com\shop\MainApplication.java:21: error: cannot find symbol public class MainApplication extends Application implements ReactApplication { ^ symbol: class ReactApplication C:\Users\user\gramic\android\app\src\main\java\com\shop\MainApplication.java:23: error: cannot find symbol private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { ^ symbol: class ReactNativeHost location: class MainApplication C:\Users\user\gramic\android\app\src\main\java\com\shop\MainApplication.java:40: error: cannot find symbol public ReactNativeHost getReactNativeHost() { ^ symbol: class ReactNativeHost location: class MainApplication C:\Users\user\gramic\android\app\src\main\java\com\shop\MainActivity.java:5: error: MainActivity is not abstract and does not override abstract method getPackages() in ReactActivity public class MainActivity extends ReactActivity { ^ C:\Users\user\gramic\android\app\src\main\java\com\shop\MainApplication.java:23: error: cannot find symbol private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { ^ symbol: class ReactNativeHost location: class MainApplication C:\Users\user\gramic\android\app\src\main\java\com\shop\MainApplication.java:39: error: method does not override or implement a method from a supertype @Override ^

    package com.shop;

import android.app.Application;

import com.facebook.react.ReactApplication;
import com.oblador.vectoricons.VectorIconsPackage;
import com.corbt.keepawake.KCKeepAwakePackage;
import com.oblador.vectoricons.VectorIconsPackage;
import com.github.yamill.orientation.OrientationPackage;
import com.BV.LinearGradient.LinearGradientPackage;
import com.brentvatne.react.ReactVideoPackage;

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

    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
            new VectorIconsPackage(),
            new VectorIconsPackage(),
            new KCKeepAwakePackage(),
            new VectorIconsPackage(),
            new OrientationPackage(),
            new LinearGradientPackage(),
            new ReactVideoPackage()

      );
    }
  };

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

  @Override
  public void onCreate() {
    super.onCreate();
    SoLoader.init(this, /* native exopackage */ false);
  }
}
Jaiprakash Soni
  • 4,100
  • 5
  • 36
  • 67
Chris Henry
  • 199
  • 1
  • 1
  • 13

7 Answers7

15

First: install all dependencies using yarn or npm;

Second: use the code below to link native dependencies on iOS and Android native code;

react-native link

Third: this error can occur because you RN version is different from Android's build.gradle version. When you create a react-native app probably it create android app like:

android/app/build.gradle

implementation "com.facebook.react:react-native:+"

So, inspect you node_modules folder, look for react-native folder and look for a folder with a number, that numbers are react-native version. For me it's 0.58.3 then update android/app/build.gradle:

implementation "com.facebook.react:react-native:0.58.3"

It's All.

Marcus
  • 773
  • 8
  • 11
  • 4
    had to add this : `implementation "com.facebook.react:react-native:0.58.4"` matching the version in my package.json – Fawaz Feb 13 '19 at 12:20
  • You can use this information to set build.gradle's react-native version. – Marcus Feb 13 '19 at 15:30
  • This worked for me. Thank you. The issue just came out of the blue for me, then I realized that `react-native` had released a new version `0.59`, so I set it to `0.58.6`. – Yeshan Jay Mar 14 '19 at 09:05
8

I also had these errors when trying to upgrade React Native. I have seen people resolve those by cleaning gradlew cache (./gradlew clean in Android project folder) or deleting the whole .gradle folder (in Android project folder also).

But that did not work for me. My issue was in the android/build.gradle file. I previously had to add a maven repository for another package and had done it that way:

maven {
        // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
        url "$rootDir/../node_modules/react-native/android"

        // The following is NOT the right way
        url "https://maven.google.com"
    }

but it is said in the Android docs that every maven repository should be in its own maven {} block.

Thus the solution that worked for me was to do that:

maven {
        // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
        url "$rootDir/../node_modules/react-native/android"
    }

maven {
        url "https://maven.google.com"
    }

Hope it will help, and good luck for your react upgrade! ;)

Lorine
  • 170
  • 10
  • It's not a good ideia, react-native library and others library are in package.json on a version X so when you download from others source the version can be others different of X. – Marcus Feb 07 '19 at 21:28
  • @Marcus why isn't it a good idea? I fail to see the link between your comment and my answer as I didn't talk about library versions in it... – Lorine Mar 06 '19 at 16:34
  • 1
    Tried all other suggestions and this was the one that worked for me – TheJediCowboy Jan 01 '20 at 16:21
  • 1
    Let me tell you, You SAVED my day! – Billy Koswara Jul 01 '20 at 14:59
6

Happened to me too after detach my react-native project from Expo.

As I answered here:

My answer

in order to fix the issue I had to:

  1. in package.js I changed:

    "react-native": "https://github.com/expo/react-native/archive/sdk-29.0.0.tar.gz",

    to :

    "react-native": "^0.57.8",

  2. delete node_modules file

  3. run npm install
  4. delete '.gradle' folder from android project and sync project.
mic123456
  • 309
  • 4
  • 6
1

I had a similar issue and all the advice I found didn't help, so I'm dropping this for anyone else having the same issue.

For me it turned out to be a 3rd party package (pushwoosh-react-native-plugin) that compiled/implemented a static version of react-native in it's build.gradle file.

I managed to find it, by

  • going to my app/build.gradle
  • commented out all my compiles/implementation on dependencies
  • added them one by one until i got the same error

As said above: It turned out to be the pushwoosh build.gradle file that had the following dependency defined:

dependencies {
    ...
    compile 'com.facebook.react:react-native:0.20.1'
    ...
}

So i went ahead and changed it right on the spot to "+"

dependencies {
    ...
    compile 'com.facebook.react:react-native:+'
    ...
}

The "+" means: the latest available version where each of the leading SEMVER components match the pattern provided

SimonEritsch
  • 1,047
  • 1
  • 8
  • 22
1

The problem for me appeared after I renamed the packages in the app. I used this to rename them:

npm install react-native-rename -g
react-native-rename "MyApp" -b com.mycompany.myapp

And there were a couple of lines that I needed to update manually:

  • android/app/src/main/java/com/winryde/MainActivity.java
  • android/app/src/main/java/com/winryde/MainApplication.java
  • android/app/src/debug/java/com/winryde/ReactNativeFlipper.java

I just searched for com.companyname and changed to the new name.

Thremulant
  • 566
  • 5
  • 15
0
  1. Uninstall react-native-reanimated previous version.
  2. cd android
  3. ./gradlew clean
  4. cd ..
  5. install react-native-reanimated@2.12.0
0

I had the same issue i reslolve it with this command

npx create react app myapp
helvete
  • 2,455
  • 13
  • 33
  • 37