Android Studio - Could not determine Java version

Change this:

targetCompatibility 'JavaVersion.VERSION_1_8'
sourceCompatibility 'JavaVersion.VERSION_1_8'

to this:

targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_1_8

change distributionUrl in gradle/wrapper/gradle-wrapper.properties to new version of gradle


I faced the same issue, but on windows 7 OS. It was because multiple versions of java was present in the same location C:\Program Files\Java Java 5, 7, 8, and 9. Although the Environment variables JAVA_HOME and PATH were set to Java 8, Android studio was referring to Java 9.

My Solution, in the menu, click on File > Project Structure here, point JDK to appropriate location C:\Program Files\Java\jdk


One potential problem is that older versions of Gradle can't parse the Java version from the java -version output produced by the OpenJDK. Newer versions can (I think it was updated around Gradle 2.2; the latest, 2.9, works).