I'm running into an issue where the Gradle daemon (as started by Android Studio via the tooling API) is using a different Java version than when run via the command line.
I do not have any value set for JAVA_HOME and java is in my path:
java -version
java version "1.8.0_72"
Java(TM) SE Runtime Environment (build 1.8.0_72-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.72-b15, mixed mode)
I wrote a task to debug:
task printDebug << {
println "command: " + System.getProperty("sun.java.command");
println "JAVA_HOME: " + System.env.'JAVA_HOME';
println "Java Version: " + org.gradle.internal.jvm.Jvm.current();
}
which, when run via Studio, produces:
command: org.gradle.launcher.daemon.bootstrap.GradleDaemon 2.8
JAVA_HOME: null
Java Version: 1.7.0_71 (Oracle Corporation 24.71-b01)
but, when run via command line, produces:
command: org.gradle.wrapper.GradleWrapperMain printDebug
JAVA_HOME: null
Java Version: 1.8.0_72 (Oracle Corporation 25.72-b15)
How is the java executable used for the gradle daemon selected? How is it launched? For what it's worth, Android Studio is using the expected version of Java (1.8), as reported by 'About Android Studio'.
The Gradle daemon will use the JDK that you've selected for your project, not the JRE/JDK that is used to run IntelliJ/Android Studio.
To change this setting, open the Project Structure dialog (File->Project Structure) for your project, and update the JDK location: