Issue
I am trying to run a React native app with this command
npx react-native run-android --variant=stagingDebug --appId com.ursafe_staging
But getting this wrong environment path error
ERROR: JAVA_HOME is set to an invalid directory: C:\Program Files\Java\jdk1.8.0_202\bin
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.
Error: Command failed: gradlew.bat app:installStagingDebug -PreactNativeDevServerPort=8081
Here is my environment path looks like
and this one
Still getting the error when I run the command.
Solution
JAVA_HOME
shouldn’t point to the bin
directory. It should point to the JDK installation path.
It should be: C:\Program Files\Java\jdk1.8.0_202
, also you don't need JRE if you already have %JAVA_HOME%\bin
, see https://www.baeldung.com/java-home-on-windows-7-8-10-mac-os-x-linux
Answered By - JuanMoreno
Answer Checked By - David Marino (JavaFixing Volunteer)