Muhammad Shah Sawar
Muhammad Shah Sawar

Reputation: 65

JAVA_HOME is set to an invalid directory- vs code

I have completely followed Setting up the development environment for the react-native project, now when I am running the first app from Andriod studio run BUTTON it installs and runs perfectly. The problem comes when I run the command yarn react-native run-android it throws the following error:


info JS server already running

info Installing the app...

ERROR: JAVA_HOME is set to an invalid directory: C:\Program Files\Java\jdk-15.0.1;C:\Program Files\Java\jdk-15.0.1\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. Run CLI with --verbose flag for more details.

    Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this co

snapshot is here

My jdk path: C:\Program Files\Java\jdk-15.0.1; C:\Program Files\Java\jdk-15.0.1\bin;

My question is:

If the jdk path is invalid then why it is running in android studio?

Upvotes: 1

Views: 15555

Answers (3)

BurhanY
BurhanY

Reputation: 91

I was getting this error in flutter. I deleted the "JAVA_HOME" "C:\Program Files\Java\jre7" value that I wrote earlier in the system variables section under the environment variables menu. I ran the terminal again and ran "flutter doctor --android-licenses" in the terminal. Problem solved. enter image description here

Upvotes: 1

Sudarshan Gaikwad
Sudarshan Gaikwad

Reputation: 579

It seems the terminal caches the earlier environment variables. Before moving ahead make sure you have already changed the correct path for JAVA_HOME.

Now, Open Visual code and close the terminal, and reopen it (ctrl + ~) error should be gone

Upvotes: 3

Rojhat
Rojhat

Reputation: 69

You should edit your path as "C:\Program Files\Java\jdk-15.0.1" bin is not required.

To set JAVA_HOME
1-Search for Environment Variables
2-Under system variables click new
3-In the variable name enter JAVA_HOME, in the variable value enter the JDK path
which is "C:\Program Files\Java\jdk-15.0.1"

Upvotes: 3

Related Questions