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

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?
Quick answer:: change JAVA_HOME variable to \jbr

Seems like it has to do with Android studio installer. if you will look closely into your "C:\Program Files\Android\Android Studio\jre\bin" folder it will probably be empty!
now check "C:\Program Files\Android\Android Studio\jbr\bin" you will see many java related ".exe" files and other files. change JAVA_HOME variable to point to the jbr.
make sure your "Path" variable also contain a %JAVA_HOME%\bin variable:

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With