skip to Main Content

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 FilesAndroidAndroid Studiojre

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?

2

Answers


  1. 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 🙂

    Login or Signup to reply.
  2. PATH environment variable must indicate to the bin directory of your JAVA_HOME, for example they should look like this:

    JAVA_HOME: "C:Program FilesJavajdk1.8.0_301"
    PATH: "C:Program FilesJavajdk1.8.0_301bin"

    Note that the PATH variable has other values too and you must append your value to it.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search