I tried running ./gradlew
from an Android project directory, but I get an error of:
ERROR: JAVA_HOME is set to an invalid directory: /Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home
Please set the JAVA_HOME variable in your environment to match the location of your Java installation.
Things I've tried:
Navigated to
/Library/Java/JavaVirtualMachines
.jdk1.8.0_11.jdk
exists, but so doesjdk1.7.0_79.jdk
which java
prints out/usr/bin/java
printenv
prints
...
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home JDK_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home
...
javac -version
printsjavac 1.8.0_11
which javac
prints/usr/bin/javac
I have added the following to my
.bash_profile
to help sort out issues such as this one. This has the added benefit of being able to runsetjdk {version}
and switch java versions on the fly.Check if /usr/libexec/java_home exists. If it does then try running
and rerunning your gradlew build. If it works then make it permanent with