IntelliJ Build Error Context Mismatch

JavaAndroidAndroid StudioIntellij Idea

Java Problem Overview


I want to use IntelliJ IDEA 15 instead of Android Studio, but I have a problem with building. I get the following error:

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 15.0\jre,daemonRegistryDir=C:\Users\Tim\.gradle\daemon,pid=1224,idleTimeout=null,daemonOpts=-XX:MaxPermSize=256m,-XX:+HeapDumpOnOutOfMemoryError,-Xmx1024m,-Dfile.encoding=windows-1252,-Duser.country=DE,-Duser.language=de,-Duser.variant]
Actual: DefaultDaemonContext[uid=6fd89265-5686-4337-a75f-538209464d3a,javaHome=C:\Program Files\Java\jdk1.8.0_74,daemonRegistryDir=C:\Users\Tim\.gradle\daemon,pid=14128,idleTimeout=10800000,daemonOpts=-XX:MaxPermSize=256m,-XX:+HeapDumpOnOutOfMemoryError,-Xmx1024m,-Dfile.encoding=windows-1252,-Duser.country=DE,-Duser.language=de,-Duser.variant]
     

What is my mistake? As you can see on the following pictures everything is configured correctly.

I have configured a JDK and the Android Tools as follows:

Project SDK2 SDK1

Java Solutions


Solution 1 - Java

I found this question while investigating a similar problem, and I solved mine, so maybe my experience will help.

Observations

My problem was similar to yours in that the Wanted context had the javaHome as the path to the JRE embedded in the IDEA install folder, and the Actual context had it as the first version of Java on my path. I found several similar error reports online but none had the IDEA embedded JRE as the Wanted version.

The Wanted Java version happened to be a system-wide install of the JRE, and not the JDK I had configured for the project, nor the value set for JAVA_HOME, which made me very suspicious (and confused). Re-ordering my path caused it to use yet another "unwanted" version of Java, so it was clearly using the path to choose what to run, but it wasn't clear why. I couldn't make IntelliJ's embedded JRE be first on my path, because I needed that to be the JDK for various reasons, so I needed another solution.

I also noticed (using Process Explorer, since I'm on Windows) that, in the failing case, IntelliJ launched a number of java.exe Gradle daemon processes, and that there were definitely no daemon processes running before I tried to start my build.

Solution

The cause turned out to be that I had defined a new configuration in the "Run/Debug Configurations" dialog and put the full path to the build.gradle file in the Gradle project: field, as follows. (I did this by clicking the ellipsis (...) button to the right of the field, but I could also have entered it directly.)

Run/Debug Configurations dialog showing Gradle project as an explicit path to a Gradle build file

However, what I should have done was follow the pattern in existing configurations, where the Gradle project: was specified as a "registered project", by clicking the "folder" icon to the right of the field, highlighted in green in the following image. In this case, the content of the field is just the project name, and is shown with subtly different background/foreground colours. (I accidentally discovered that right-clicking on this name will replace it with the path to the folder containing build.gradle, but if you cancel and start editing the configuration again, it will still appear as just the project name.)

Run/Debug Configurations dialog showing Gradle project as the name of a registered project

After making this change, the configuration built as expected, and I observed that only one java.exe was launched, using the same JDK path as when I ran tasks from the "Gradle" panel in the UI.

Solution 2 - Java

I solved it by using idea64.exe and not idea.exe

enter image description here

Solution 3 - Java

  1. Create file gradle.properties in folder %USERPROFILE%\.gradle\ (~/.gradle/ on *nix machines)
  2. In this file add string org.gradle.java.home={actual path to jdk} (to know it in MacOS run /usr/libexec/java_home)

Solution 4 - Java

For me this issue was solved by running IDE in 64 bit mode since I only have 64 bit JRE installed.

Solution 5 - Java

I had the exact same problem and this is what worked for me.

I deleted the .idea and .project files from the root directory of my IntelliJ project. Restarted IntelliJ and opened my project again.

Solution 6 - Java

For MacOSX, what solved the problem for me was to point the SDK in IntelliJ to Contents/Home. For example:

This:

> /Users//.sdkman/candidates/java/14.0.1-zulu/zulu-14.jdk/Contents/Home

instead of this:

> /Users//.sdkman/candidates/java/14.0.1-zulu

It is working with the latest, at this time, Java (14.0.1-zulu), Gradle (6.5) and Kotlin (1.4-M2).

Solution 7 - Java

Add below in your gradle.propetries

org.gradle.java.home=${sdk_path}

for example:

org.gradle.java.home=C:\Program Files (x86)\Java\jdk1.8.0_121

Otherwise if you have memory heap warning.

Please also add gradle.properties with below: org.gradle.jvmargs=-Xmx512m

Solution 8 - Java

What worked for me was:

  • uninstalling intelliJ
  • Re-install intelliJ, but during the installation make sure you DON'T check "Download and install 64-bit JRE by JetBrains (will be used with the 64-bit launcher)"

This made my project work again, (in both he 32 and 64 bit version).

Solution 9 - Java

I solved it by using 11.0.8-amzn instead of 11.0.8-zulu.

Cost me two hours of my life to get the builds working again in the IDE

Solution 10 - Java

In my case I only went to settings, searched for JDK, clicked Java Compiler, then I noticed the project bytecode version was missing. So I only checked 1.8 which is my Java build version. And that was it for me.

enter image description here

Solution 11 - Java

just move the jdk folder to intellij wanted folder C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2016.3.4\jre

then change the values in .gradle folder given in wanted line close the project then restart

it works for me....

Solution 12 - Java

I solved this problem by renaming jre and jre64 folders to prevent idea from using them and setting JAVA_HOME to my other JDK 1.8 installation in the idea.bat file.

Solution 13 - Java

If you're using the Gradle IDEA plugin:

  1. Run .\gradlew cleanidea idea
  2. Quit IntelliJ IDEA
  3. Start IntelliJ IDEA and choose the "Import Project" option from the main menu.
  4. Navigate to your project's main build.gradle file when asked to specify the project to import.
  5. You'll then get the chance to set the JDK to "the project default" or another preferred JDK.
  6. Click OK to continue, and watch Gradle sync and build again successfully!

Solution 14 - Java

For me the problem got solved when I switched from 11.0.14-zulu to another vendor of java 11.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questiontimia2109View Question on Stackoverflow
Solution 1 - JavaHughGView Answer on Stackoverflow
Solution 2 - JavaPercy VegaView Answer on Stackoverflow
Solution 3 - JavaVladyslav VynnykView Answer on Stackoverflow
Solution 4 - JavaArthur CarrollView Answer on Stackoverflow
Solution 5 - JavaAbdullah KhanView Answer on Stackoverflow
Solution 6 - JavaGarouDanView Answer on Stackoverflow
Solution 7 - JavaDanteView Answer on Stackoverflow
Solution 8 - JavaLindsay-Needs-SleepView Answer on Stackoverflow
Solution 9 - Javaaqab0NView Answer on Stackoverflow
Solution 10 - JavaJuan MendezView Answer on Stackoverflow
Solution 11 - JavaHafiz umerView Answer on Stackoverflow
Solution 12 - JavaKrishnaView Answer on Stackoverflow
Solution 13 - JavaAdil BView Answer on Stackoverflow
Solution 14 - JavaArsenView Answer on Stackoverflow