I am using gradle within an Android project on Windows.
When I execute ./gradlew -version
within my project path, error is shown as Could not determine java version from '12'.
I did have both Java 8 and 12 installed on my machine but my JAVA_HOME
variable is set to jdk1.8 path, the JDK location in Android Studio is also set to jdk1.8. as show below. If I call java -version
from cmd I could also get version 1.8 instead of version 12.
So why does gradle get a wrong version of Java? Is there any other configuration that might lead to this result?
Gradle version is 4.1 but I prefer not to update it.
Please try this.
Please change your JAVA path (from jdk1.8 to jdk12) in your computer from properties.
Go to Computer Properties -> Advanced System setting -> Environment variable -> Edit Path - C:\Program Files\Java\jdk-10.0.1\bin
Then restart your PC and android studio and check jdk location in android studio.
I tried to uninstall Java 12 from my machine, and gradle report JAVA_HOME = JAVA_12_DIR is empty, which means JAVA_HOME is still not updated somehow.
So I restart the machine, and the Java version is correctly specified now.
The reason is probably that I did not shut all my cmd and running java programs down. So JAVA_HOME is not properly updated. Although in a new cmd window, the newly updated JAVA_HOME can be found.
Please refer to this answer for environmental variable updating detail.
No, but you will need to close and recreate any cmd windows, running java programs, or the like.
To check it's correct, open a new cmd window and type set -> review the information for PATH and JAVA_HOME.