25

Could not find the "expo" package in your project when configuring the packager Starting JS server... Building and installing the app on the device (cd android && ./gradlew installDebug)...

Task :app:compileDebugJavaWithJavac FAILED /media/rahul/OTHER FILES/mob/first/android/app/src/main/java/com/practice/MainApplication.java:5: error: cannot find symbol import com.facebook.react.ReactApplication; ^ symbol: class ReactApplication location: package com.facebook.react /media/rahul/OTHER FILES/mob/first/android/app/src/main/java/com/practice/MainApplication.java:6: error: cannot find symbol import com.facebook.react.ReactNativeHost; ^ symbol: class ReactNativeHost location: package com.facebook.react /media/rahul/OTHER FILES/mob/first/android/app/src/main/java/com/practice/MainApplication.java:14: error: cannot find symbol public class MainApplication extends Application implements ReactApplication { ^ symbol: class ReactApplication /media/rahul/OTHER FILES/mob/first/android/app/src/main/java/com/practice/MainApplication.java:16: error: cannot find symbol private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { ^ symbol: class ReactNativeHost location: class MainApplication /media/rahul/OTHER FILES/mob/first/android/app/src/main/java/com/practice/MainApplication.java:36: error: cannot find symbol public ReactNativeHost getReactNativeHost() { ^ symbol: class ReactNativeHost location: class MainApplication /media/rahul/OTHER FILES/mob/first/android/app/src/main/java/com/practice/MainActivity.java:5: error: MainActivity is not abstract and does not override abstract method getPackages() in ReactActivity public class MainActivity extends ReactActivity { ^ /media/rahul/OTHER FILES/mob/first/android/app/src/main/java/com/practice/MainApplication.java:16: error: cannot find symbol private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { ^ symbol: class ReactNativeHost location: class MainApplication /media/rahul/OTHER FILES/mob/first/android/app/src/main/java/com/practice/MainApplication.java:35: error: method does not override or implement a method from a supertype @Override ^ 8 errors

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. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

BUILD FAILED in 22s 15 actionable tasks: 14 executed, 1 up-to-date 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

i am setting up react-native project for first time please check if i am following steps correctly? 1. create-react-native-app first 2. npm run eject 3. opening android studio and then simulator 4. react-native run-android but getting error as above.

1
  • 2
    So, scroll up to see more details. Or run it with one of those flags like it recommends
    – Kai
    Jan 30, 2019 at 18:31

11 Answers 11

29

This error 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.

4
  • 1
    "look for a folder with a number" - do you mean get the version number from package.json? ..this didnt work for me
    – conor909
    Feb 22, 2020 at 13:51
  • 4
    I think he is talking about : "project_folder\node_modules\react-native\android\com\facebook\react\react-native\", there I found a folder with numbers... I tried this, but it was not the solution for my case Feb 27, 2020 at 3:28
  • 4
    You can also look at your package.json for you react-native version Mar 19, 2021 at 20:49
  • 1
    Why does your solution work? Dec 15, 2021 at 14:10
13

If you are here because of this React Native error:

> Task :react-native-community_toolbar-android:compileDebugJavaWithJavac FAILED

The solution is updating the @react-native-community/toolbar-android to version 0.2.1

10

You should provide more info. The error you've posted is not very helpful.

Without more info, you could try to:

cd android && ./gradlew clean

and see if it helps.

3
  • I went to he project folder in command line and pasted this command. It says it does not recognize the . command as internal or external command. Can you please provide some more detail how did you resolve this?
    – Paras
    May 6, 2020 at 14:56
  • try gradlew clean
    – SHARAD
    Sep 19, 2020 at 4:58
  • not helping, tried many times
    – bra.Scene
    Feb 23, 2023 at 14:57
4

For what it's worth, I ended here googling my similar compile problem and the issue was that an OS update had wiped Java JDK from my path. Fixing that solved the issue.

3

I also had a similar crash report. But in my case the issue was a missing environment variable for JAVA_HOME. I set it to the same path as in Android Studio and that fixed the issue: File -> Project Structure -> SDK Location -> JDK location.

export JAVA_HOME="/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home"
1
  • It helped me. But in Android Studio 2023 you need to go to "Android Studio -> Settings -> Build, Execution, Deployment, Build Tools, Gradle -> <your project> -> Gradle JDK" Dec 13, 2023 at 9:30
2

[For people who are brought here by Google]

In my case, the error appeared after I try to link @react-native-async-storage/async-storage using react-native link.

I initialized my project using React Native CLI, which was a few minor versions behind. But I linked the dependency with npx react-native link. Version Mismatch!

To the best of my knowledge, this is the root cause of that error.

You are most likely to make changes inside android/app/src/main/java/com/focustime/MainApplication.java and android/settings.gradle. If you are developing with git, simply checkout those two files.

Following are the changes that RN link introduced:

diff --git a/android/app/src/main/java/com/focustime/MainApplication.java b/android/app/src/main/java/com/focustime/MainApplication.java
index ed18f44..2bdc42c 100644
--- a/android/app/src/main/java/com/focustime/MainApplication.java
+++ b/android/app/src/main/java/com/focustime/MainApplication.java
@@ -4,6 +4,7 @@ import android.app.Application;
 import android.content.Context;
 import com.facebook.react.PackageList;
 import com.facebook.react.ReactApplication;
+import com.reactnativecommunity.asyncstorage.AsyncStoragePackage;
 import com.facebook.react.ReactInstanceManager;
 import com.facebook.react.ReactNativeHost;
 import com.facebook.react.ReactPackage;
diff --git a/android/settings.gradle b/android/settings.gradle
index 20ccd07..f6f51cd 100644
--- a/android/settings.gradle
+++ b/android/settings.gradle
@@ -1,3 +1,5 @@
 rootProject.name = 'FocusTime'
+include ':@react-native-async-storage_async-storage'
+project(':@react-native-async-storage_async-storage').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-async-storage/async-storage/android')
 apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
 include ':app'
2

In my case

My React native version is 0.62.2

and

    buildToolsVersion = "31.0.0"
    minSdkVersion = 21
    compileSdkVersion = 31
    targetSdkVersion = 31
    supportLibVersion = "28.0.0"

so I just update the compiledSdkVersion and targetSdkVersion

    buildToolsVersion = "31.0.0"
    minSdkVersion = 21
    compileSdkVersion = 33
    targetSdkVersion = 33
    supportLibVersion = "28.0.0"

Android 13 support the compiledSdkVersion and targetSdkVersion should be changed to 33

1
  • There are 2 places inside android/build.gradle with compileSdkVersion: buildscript.ext.compileSdkVersion and ext.compileSdkVersion, the first one was 33, the second left 31. Changed to 33 both and all worked (the issue was with "react-native-ble-plx": "^3.1.2" package ) Apr 10 at 9:36
1

This happens to me because I forget to install some modules.

And I run:

1. npm install

2. npx react-native run-android

OBS: you can run npx react-native link too. To link your modules.

1
  • npx react-native link doesn't work on RN version 0.73.x : error: unknown command 'link' Mar 1 at 14:24
1

Most of the times this is due the Configuration of the ANDROID_HOME is not done properly. And other times this due the gradle version miss-match

if you are using zsh which is default for newer Mac open terminal and type these commands

nano ~/.zshrc or vim ~/.zshrc

and paste these three lines

export ANDROID_HOME=$HOME/Library/Android/sdk

export PATH=$PATH:$ANDROID_HOME/emulator

export PATH=$PATH:$ANDROID_HOME/platform-tools

save the file and then run

source ~/.zshrc

close the terminal fully and run your emulator

0

I solved this issue by first check your all JAVA Environment variables are properly set or not otherwise set:

>  JAVA_HOME : C:\Program Files\Java\jdk1.8.0_112
>          JDK_HOME  : %JAVA_HOME%
>          JRE_HOME  : %JAVA_HOME%\jre
>          CLASSPATH : .;%JAVA_HOME%\lib;%JAVA_HOME%\jre\lib
>          PATH      : ....;%JAVA_HOME%\bin

then I added jdk path:

org.gradle.java.home=C:\Program Files\Java\jdk1.8.x.x

to gradle.properties

Finally, I've ran in the terminal:

cd android &&./gradlew clean
cd .. && react-native run-android
0

When I faced this issue in my React Native project, I did some useful steps. Follow them as:

  1. In my terminal, move to the android folder by typing cd android
  2. Then type ./gradlew clean. It will take 1 min approx.
  3. Return back to root folder by typing .. cd
  4. Run this command to rebuilt npx react-native run-android

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.