Below are the Gradle specs:
After r
I was able to solve this issue by reading the output log from the gradle daemon and below is the relevant line that helped me fix it.
14:52:50.575 [INFO] [org.gradle.launcher.daemon.server.Daemon] start() called on daemon - DefaultDaemonContext[uid=03e55abd-dc5a-42c5-bc7f-fc25f6a78bcb,javaHome=/Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home,daemonRegistryDir=/Users/user_name/.gradle/daemon,pid=16809,idleTimeout=10800000,daemonOpts=-Xmx1536m,-Dfile.encoding=UTF-8,-Duser.country=US,-Duser.language=en,-Duser.variant]
So, the gist is that the gradle settings and Android Studio settings work independent of each other. Gradle relies on the JAVA_HOME env var while starting up a daemon and making your build, when org.gradle.java.home isn't explicitly set in properties.
Therefore, when rolling back to a different JVM, make sure to set the JAVA_HOME env var to that specific JVM (if you use the same JVM across all your applications) or set daemon specific setting like below in your gradle.properties file visible at the project level :
org.gradle.java.home=/Library/Java/JavaVirtualMachines//Contents/Home
Please note that the above is my path and I use a Mac. It may be different on other platforms.