Search code examples
androidandroid-studiojava-home

Android Studio , on windows : JAVA_HOME is not set and no 'java' command could be found in your PATH


I am trying to build my Android app on the command line using Gradle commands. On executing the .gradlew build I am getting the error below:

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.

but I think I have already set the JAVA_HOME Path. If I echo %JAVA_HOME% in a separate cmd.exe window I get:

C:\Program Files\Android\Android Studio\jre

The location above is set as the JDK location

I have to point the JAVA_HOME to the JRE provided by Android and not the system Java, right?

Also, when I run the java command, it shows

'java' is not recognized as an internal or external command, operable program or a batch file

java  -version
java version "1.8.0_271"
Java(TM) SE Runtime Environment (build 1.8.0_271-b09)
Java HotSpot(TM) Client VM (build 25.271-b09, mixed mode, sharing)

Please clarify?


Solution

  • I understood your problem, add your JDK (Not JRE) path to the PATH variable in environment variables. Then run the java command, and it should run. And whenever you post a question, please do make sure that you mention details like what happens when you run java command :)