After Android Studio sync my gradle project, I see the following message in the event log:
Android Studio is using this JDK location:
I'm running Windows and had the same error when upgrading to AS 3.6.1.
As well as Android projects I also build Java projects on the same machine, both of which use different versions of Java. So pointing AS / Gradle wrapper to my JAVA_HOME is not an option.
To solve the problem I need my environment variable JAVA_HOME to point to my Java projects and JAVA_HOME for AS / Gradle to point to the version of the JRE shipped with AS.
There is a simple solution. Its a bit messy, but it works. To do this you will need to be able to see hidden files. Then mod the Gradle wrapper batch file as follows:
C:/Users/your_user_name/.gradle/wrapper/dists/the_latest_gradle_version(mine is 5.6.4)/bxirm19lnfz6nurbatndyydux/gradle-5.6.4/bin/gradle.bat
Go to the function:
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
And change to:
:findJavaFromJavaHome
set JAVA_HOME=%C:/Program Files/Android/AndroidStudio/jre:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
This isn't a permanent solution, as it may well be overwritten with new versions of Gradle, however it works for now and hopefully long enough for someone (hopefully Google) to point AS and is Gradle wrappers to the correct location by default.