react-native: Error on running react-native project : MainApplication.java:5: error: cannot find symbol import com.facebook.react.ReactApplication;
I have created project using expo ie expo init helloworld
then ejected it using expo eject
.
And then I tried to run in emulator with yarn run android
.
I got the following error.
$ yarn run android yarn run v1.3.2 $ react-native run-android Scanning folders for symlinks in D:\gajurlab\helloworld\node_modules (25ms) JS server already running. Building and installing the app on the device (cd android && gradlew.bat installDebug)… Incremental java compilation is an incubating feature. :app:preBuild UP-TO-DATE :app:preDebugBuild UP-TO-DATE :app:checkDebugManifest :app:preReleaseBuild UP-TO-DATE :app:prepareComAndroidSupportAppcompatV72301Library UP-TO-DATE :app:prepareComAndroidSupportRecyclerviewV72301Library UP-TO-DATE :app:prepareComAndroidSupportSupportV42301Library UP-TO-DATE :app:prepareComFacebookFrescoDrawee081Library UP-TO-DATE :app:prepareComFacebookFrescoFbcore081Library UP-TO-DATE :app:prepareComFacebookFrescoFresco081Library UP-TO-DATE :app:prepareComFacebookFrescoImagepipeline081Library UP-TO-DATE :app:prepareComFacebookFrescoImagepipelineOkhttp081Library UP-TO-DATE :app:prepareComFacebookReactReactNative0201Library UP-TO-DATE :app:prepareOrgWebkitAndroidJscR174650Library UP-TO-DATE :app:prepareDebugDependencies :app:compileDebugAidl UP-TO-DATE :app:compileDebugRenderscript UP-TO-DATE :app:generateDebugBuildConfig UP-TO-DATE :app:mergeDebugShaders UP-TO-DATE :app:compileDebugShaders UP-TO-DATE :app:generateDebugAssets UP-TO-DATE :app:mergeDebugAssets UP-TO-DATE :app:generateDebugResValues UP-TO-DATE :app:generateDebugResources UP-TO-DATE :app:mergeDebugResources UP-TO-DATE :app:bundleDebugJsAndAssets SKIPPED :app:processDebugManifest UP-TO-DATE :app:processDebugResources UP-TO-DATE :app:generateDebugSources UP-TO-DATE :app:incrementalDebugJavaCompilationSafeguard UP-TO-DATE :app:compileDebugJavaWithJavac :app:compileDebugJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.). D:\gajurlab\helloworld\android\app\src\main\java\com\mynewproject\MainApplication.java:5: error: cannot find symbol import com.facebook.react.ReactApplication; ^ symbol: class ReactApplication location: package com.facebook.react D:\gajurlab\helloworld\android\app\src\main\java\com\mynewproject\MainApplication.java:6: error: cannot find symbol import com.facebook.react.ReactNativeHost; ^ symbol: class ReactNativeHost location: package com.facebook.react D:\gajurlab\helloworld\android\app\src\main\java\com\mynewproject\MainApplication.java:14: error: cannot find symbol public class MainApplication extends Application implements ReactApplication { ^ symbol: class ReactApplication D:\gajurlab\helloworld\android\app\src\main\java\com\mynewproject\MainApplication.java:16: error: cannot find symbol private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { ^ symbol: class ReactNativeHost location: class MainApplication D:\gajurlab\helloworld\android\app\src\main\java\com\mynewproject\MainApplication.java:36: error: cannot find symbol public ReactNativeHost getReactNativeHost() { ^ symbol: class ReactNativeHost location: class MainApplication D:\gajurlab\helloworld\android\app\src\main\java\com\mynewproject\MainActivity.java:5: error: MainActivity is not abstract and does not override abstract method getPackages() in ReactActivi ty public class MainActivity extends ReactActivity { ^ D:\gajurlab\helloworld\android\app\src\main\java\com\mynewproject\MainApplication.java:16: error: cannot find symbol private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { ^ symbol: class ReactNativeHost location: class MainApplication D:\gajurlab\helloworld\android\app\src\main\java\com\mynewproject\MainApplication.java:35: error: method does not override or implement a method from a supertype @Override ^ 8 errors :app:compileDebugJavaWithJavac FAILED
FAILURE: Build failed with an exception.
- What went wrong: Execution failed for task ‘:app:compileDebugJavaWithJavac’.
Compilation failed; see the compiler error output for details.
- Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 9.46 secs Could not install the app on the device, read the error above for details. Make sure you have an Android emulator running or a device connected and have set up your Android development environment: https://facebook.github.io/react-native/docs/getting-started.html Done in 12.38s.
Info
$ react-native info Scanning folders for symlinks in D:\gajurlab\helloworld\node_modules (25ms)
Environment: OS: Windows 8.1 Node: 8.9.4 Yarn: 1.3.2 npm: 5.6.0 Watchman: Not Found Xcode: N/A Android Studio: Version 3.1.0.0 AI-173.4720617
Packages: (wanted => installed) react: 16.3.1 => 16.3.1 react-native: https://github.com/expo/react-native/archive/sdk-30.0.0.tar.gz => 0.55.4
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 20
- Comments: 36 (2 by maintainers)
I solved it by: change the line below in android/app/build.gradle file from implementation “com.facebook.react:react-native:+” // From node_modules to specific version of my react-native as in package.json implementation “com.facebook.react:react-native:0.57.5” // From node_modules
I had the same problem - adding the following block to
allprojects.repositories
in the project’sbuild.gradle
fixed it for me:Versions Android Studio: 3.4 Canary 10 gradle: 5.1 react-navive: 0.57.8
I have the same issue. Seems like “android” folder is missing referenced here:
Same here. No android folder in react-native/ Java compiler displays : cannot find symbol class ReactApplication and cannot find symbol ReactNativeHost.
Any update ?
@basha777 try adding to the bottom of your app/build.gradle
I’m having this error:
npmPackages: react: 16.8.6 => 16.8.6 react-native: 0.60.4 => 0.60.4 npmGlobalPackages: react-native-cli: 2.0.1 react-native-git-upgrade: 0.2.7
react-native@0.60.4 └── @react-native-community/cli@2.8.3
com.android.tools.build:gradle:3.4.1
dependencies { implementation fileTree(dir: “libs”, include: [“*.jar”]) implementation “com.facebook.react:react-native:+” … }
I’ve been updating RN 0.55.4 -> 0.60.4
I had the same problem, follow the link: node_modules/react-native/android/com.facebbok.react/react-native. You can see the react-native version. after: change (build.gradle(app)): (implementation “com.facebook.react:react-native:+”) -> (implementation “com.facebook.react:react-native:0.58.4”) My version: 0.58.4 it worked for me.
Getting very similar error within packageList (also get in MainApplication if link in there):
(For now removed as not essential)
while upgrading to from RN 0.59.9 to 0.60.5 using https://react-native-community.github.io/upgrade-helper/?from=0.59.9&to=0.60.5 i forgot to make changes in android/app/build.gradle file, after making the following changes my issue was solved Note: by default android/app/build.gradle is not expanded.
@phorvicheka doesnt works
Edit
This was the reason https://github.com/facebook/react-native/issues/21722#issuecomment-438819200
In my case, the problem is solved by appending
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
at the bottom ofandroid/app/build.gradle
.facing same issue while upgrade from RN 0.59.9 to 0.60.5.
OK, I’ve figured out the problem, at least in my case.
Running
./gradlew app:dependencies
shows thatreact-native-sound
specifies an ancient RN version, and that’s taking precedence.What I can’t work out is why it resolves correctly if I go back to the commit before the upgrade:
Maybe a change in resolution rules on the newer gradle version that ships with 0.58?
Same as ChaabaneFahmi for me!
At the end, I stopped trying using expo and then eject the app, instead of that, I used the option “Build Projects with native code” from React Native official page, https://facebook.github.io/react-native/docs/getting-started...and It worked like expected
I have the same problem…and I looked into node_modules/react-native and there is no “android” folder like it used to be in previous version, did you find any solution?