4

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'.

Will
  • 24,082
  • 14
  • 97
  • 108
jbluntz
  • 78
  • 7
  • What does the Project Structure dialog (File->Project Structure) show for JDK location? – Sam Dozor Mar 01 '16 at 20:38
  • @SamDozor you win... I looked all over for that setting! Still getting used to IntelliJ as a long time Eclipse user. Convert your comment to an answer so I can accept it! – jbluntz Mar 02 '16 at 03:14

1 Answers1

2

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:

enter image description here

Sam Dozor
  • 40,335
  • 6
  • 42
  • 42