in Android

How to fix gradle in Intellij IDEA

When starting a project in Intellij IDEA if you see an error around the lines of

Gradle sync failed: The newly created daemon process has a different context than expected.
 It won't be possible to reconnect to this daemon. Context mismatch: 
 Java home is different.
 Wanted: DefaultDaemonContext[uid=null,javaHome=C:\Program Files (x86)\JetBrains\IntelliJ IDEA 2016.3.2\jre,daemonRegistryDir=C:\Users\Ronald\.gradle\daemon,pid=7044,idleTimeout=null,daemonOpts=-Xmx1536m,-Dfile.encoding=windows-1252,-Duser.country=US,-Duser.language=en,-Duser.variant]
 Actual: DefaultDaemonContext[uid=7819e5ac-98ac-4dd2-8891-cacf4e56f662,javaHome=C:\Program Files\Java\jdk1.8.0_112,daemonRegistryDir=C:\Users\Ronald\.gradle\daemon,pid=4720,idleTimeout=60000,daemonOpts=-Xmx1536m,-Dfile.encoding=windows-1252,-Duser.country=US,-Duser.language=en,-Duser.variant]
 Consult IDE log for more details (Help | Show Log)

The solution would be to explicitly tell grade where your java directory is. You can do this in two places

  1. Open up %USERPROFILE%\.gradle\  and create the file gradle.properties
  2. In your android project create or edit the gradle.properties file

Inside that file put the location of your java path using forwardslashes instead of backslashes

org.gradle.java.home=Your/path/here/with/forwardslashes

In my case it looks like:

org.gradle.java.home=C:/Program Files/Java/jdk1.8.0_112

Write a Comment

Comment