I have Java 8 and 9 installed on my machine, I did not have problems until one day I tried to run gradle command. I google for the answer of course, some suggested to remove Java 9. But I did not like to mess up the system by installing/uninstalling software. So I changed JAVA_HOME to point java 8, and the problem solved.
Environment
- macOS
Fix
JAVA_HOME was set to point to the latest Java in ~/.bash_profile
export JAVA_HOME=$(/usr/libexec/java_home)
# java -version
java version "9.0.1"
Java(TM) SE Runtime Environment (build 9.0.1+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)
Gradle throws error
* What went wrong:
A problem occurred configuring project ':app'.
> Failed to notify project evaluation listener.
> Could not initialize class com.android.sdklib.repository.AndroidSdkHandler
Change JAVA_HOME to point to Java 8
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home
To view the specific version of Java installed, look the directory /Library/Java/JavaVirtualMachines/
# source ~/.bash_profile
# java -version
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)