react-native can not find JAVA_HOME - react-native

After initializing my project with react-native init AwesomeProject I try to run it in the simulator via react-native run-android
However I get the following error:
ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.
error Failed to install the app. Make sure you have the Android development environment set up: https://facebook.github.io/react-native/docs/getting-started.html#android-development-environment.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
However I followed the Getting Started Guide and the JAVA_HOME Evironmental Variable is set and C:\Program Files\Java\jdk1.8.0_221\bin is also in the Path var.
I am trying this on Windows 10 with the WSL bash.

I was able to fix this by creating a new project. The problem was that I run react-native init AwesomeProject from the WSL bash in windows. I could reproduce this.
When running the same init command in the command prompt it works.

Related

React native- run android

When placing react-native run-android it marks me this error: error The application could not be installed. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run the CLI with the --verbose flag for more details.
Error: command failed: application gradlew.bat: installDebug -PreactNativeDevServerPort = 8081
the emulator I am using is the Genymotion
As it says follow the steps of setupping environment https://reactnative.dev/docs/environment-setup
Also, I can advise you to check your bash profile if you are using macOS.
Crete bash profile if it is not created by: touch ~/.bash_profile; in the terminal.
And after run in terminal to open open ~/.bash_profile

I am trying to run AVD with react-native, but an unknown variable error appears

I am trying to run the code created through react-native as AVD in android studio, but I am getting an error about the variable JAVA_HOME. What should I do?
ERROR: JAVA_HOME is set to an invalid directory: C:\Program Files\Java\jdk1.8.0_131
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
Sometime we need to manually set the path (environment) of JAVA_JDK . Install latest JAVA JDK from official website. And set the path of jre and bin folder. After looking your directory C:\Program Files\Java\jdk1.8.0_131 I guess you are on windows , So I'm not sure how to set environment variable for windows but definitely you could get help from youtube.

Android development environment set up issue came while trying to run react native app

I am currently trying to run react native application but I am getting this error in windows 10.
ERROR: JAVA_HOME is set to an invalid directory: C:\Program Files\Java\jdk1.8.0_251;
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.
error Failed to install the app. Make sure you have the Android development environment set up: https://facebook.github.io/react-native/docs/getting-started.html#android-development-environment. Run CLI with --verbose flag for more details.Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
at checkExecSyncError (child_process.js:630:11)
at execFileSync (child_process.js:648:15)
at runOnAllDevices (C:\Users\User\Desktop\crate\crate\code\mobile\node_modules\#react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:94:39)
at buildAndRun (C:\Users\User\Desktop\crate\crate\code\mobile\node_modules\#react-native-community\cli-platform-android\build\commands\runAndroid\index.js:179:41)
at C:\Users\User\Desktop\crate\crate\code\mobile\node_modules\#react-native-community\cli-platform-android\build\commands\runAndroid\index.js:133:12
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async Command.handleAction (C:\Users\User\Desktop\crate\crate\code\mobile\node_modules\react-native\node_modules\#react-native-community\cli\build\index.js:182:9)
I already install java and its working like in this image
Also, I run emulator before using this code react-native run-android like in this image
it also giving me this error but the emulator working.
Failed to open /qemu.conf, err: 2
What the wrong move that I did in this situation?
You can checkout the same question at this. Edit your environmental variable.
Go to User Variables and Edit the path and add %JAVA_HOME%\bin.
Now in your system variable environments: edit the path and click new and add this C:\Program Files\Java\jdk1.8.0_241\bin
Again in system variable environment click on the path and click on new add this line C:\Program Files (x86)\Common Files\Oracle\Java\javapath
Now save and restart your system. this would help you.
You need to setup the JAVA_HOME environment variable that will be called when running react native android build.
Setup guide for JAVA_HOME.

Problem encountered in installing react-native

This is a react-native installation issue:
error Failed to install the app. Make sure you have the Android development environment set up: https://facebook.github.io/react-native/docs/getting-started.html#android-development-environment. Run CLI with --verbose flag for more details.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
C:\Users\eshas\AwesomeProject>react-native run-android
You need to install AndroidStudio and Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.

error occur in react-native run-android command using cmd

Scanning folders for symlinks in F:\PROJECTS\ReactNative\albums\node_modules (246ms)
Starting JS server...
Building and installing the app on the device (cd android && gradlew.bat installDebug)...
ERROR: JAVA_HOME is set to an invalid directory: C:\Program Files\Java\jdk1.8.0_144
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.
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/android-setup.html
Anyone can tell what's the problem, after I've run "react-native run-android" command.
That question's solution is type following command in cmd for following:
set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_144