React native: error: cannot find symbol after upgrade
Solution 1
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.
Solution 2
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! ;)
Solution 3
Happened to me too after detach my react-native project from Expo.
As I answered here:
in order to fix the issue I had to:
-
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",
delete node_modules file
- run npm install
- delete '.gradle' folder from android project and sync project.
Solution 4
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
Solution 5
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.
![Chris Henry](https://lh3.googleusercontent.com/-XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/photo.jpg?sz=256)
Chris Henry
Updated on May 08, 2021Comments
-
Chris Henry about 3 years
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); } }
-
Marcus over 5 yearsIt'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.
-
Fawaz over 5 yearshad to add this :
implementation "com.facebook.react:react-native:0.58.4"
matching the version in my package.json -
Marcus over 5 yearsYou can use this information to set build.gradle's react-native version.
-
Lorine over 5 years@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...
-
Yeshan Jay over 5 yearsThis 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 version0.59
, so I set it to0.58.6
. -
TheJediCowboy over 4 yearsTried all other suggestions and this was the one that worked for me
-
Billy Koswara almost 4 yearsLet me tell you, You SAVED my day!