Java IntelliJ 构建错误上下文不匹配

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35536013/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 16:48:11  来源:igfitidea点击:

IntelliJ Build Error Context Mismatch

javaandroidandroid-studiointellij-idea

提问by timia2109

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

我想使用 IntelliJ IDEA 15 而不是 Android Studio,但是我在构建时遇到了问题。我收到以下错误:

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:

我已经配置了一个 JDK 和 Android 工具,如下所示:

ProjectSDK2SDK1

项目SDK2SDK1

采纳答案by HughG

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 Wantedcontext had the javaHomeas the path to the JRE embedded in the IDEA install folder, and the Actualcontext 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 Wantedversion.

我的问题与您的问题相似,因为Wanted上下文javaHome将 JRE 作为嵌入 IDEA 安装文件夹中的路径,并且Actual上下文将其作为我路径上的第一个 Java 版本。我在网上找到了几个类似的错误报告,但没有一个将 IDEA 嵌入 JRE 作为Wanted版本。

The WantedJava 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.

WantedJava版本正好是一个全系统的安装JRE,而不是JDK我已经为该项目配置,也不需要设置的值JAVA_HOME,这让我十分可疑(和混淆)。重新排序我的路径导致它使用另一个“不需要”的 Java 版本,所以它显然是使用路径来选择要运行的内容,但不清楚为什么。我不能让 IntelliJ 的嵌入式 JRE 成为我的第一个路径,因为出于各种原因我需要它作为 JDK,所以我需要另一个解决方案。

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

我还注意到(使用 Process Explorer,因为我在 Windows 上)在失败的情况下,IntelliJ 启动了许多java.exeGradle 守护进程,并且在我尝试开始构建之前肯定没有守护进程在运行。

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.gradlefile 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.)

原因原来是我在“运行/调试配置”对话框中定义了一个新配置,并将build.gradle文件的完整路径放在Gradle project:字段中,如下所示。(我通过单击字段右侧的省略号 (...) 按钮来完成此操作,但我也可以直接输入它。)

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

运行/调试配置对话框将 Gradle 项目显示为 Gradle 构建文件的显式路径

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

但是,我应该做的是遵循现有配置中的模式Gradle project:,通过单击字段右侧的“文件夹”图标,将其指定为“注册项目”,在下图中以绿色突出显示。在这种情况下,该字段的内容只是项目名称,并以略有不同的背景/前景色显示。(我无意中发现,右键单击此名称会将其替换为包含 的文件夹的路径build.gradle,但是如果您取消并再次开始编辑配置,它仍将仅显示为项目名称。)

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

运行/调试配置对话框显示 Gradle 项目作为注册项目的名称

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

进行此更改后,配置按预期构建,我观察到只java.exe启动了一个,使用与我从 UI 中的“Gradle”面板运行任务时相同的 JDK 路径。

回答by Abdullah Khan

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

我遇到了完全相同的问题,这对我有用。

I deleted the .ideaand .projectfiles from the root directory of my IntelliJ project. Restarted IntelliJ and opened my project again.

我从 IntelliJ项目的根目录中删除了.idea.project文件。重新启动 IntelliJ 并再次打开我的项目。

回答by Arthur Carroll

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

对我来说,这个问题是通过在 64 位模式下运行 IDE 来解决的,因为我只安装了 64 位 JRE。

回答by Vladyslav Vynnyk

  1. Create file gradle.propertiesin 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)
  1. gradle.properties在文件夹中创建文件%USERPROFILE%\.gradle\~/.gradle/在 *nix 机器上)
  2. 在这个文件中添加字符串org.gradle.java.home={actual path to jdk}(在 MacOS 运行中知道它/usr/libexec/java_home

回答by Percy Vega

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

我通过使用idea64.exe而不是idea.exe解决了它

enter image description here

在此处输入图片说明

回答by Lindsay-Needs-Sleep

What worked for me was:

对我有用的是:

  • uninstalling intelliJ
  • Re-install intelliJ, but during the installation make sure you DON'Tcheck "Download and install 64-bit JRE by JetBrains (will be used with the 64-bit launcher)"
  • 卸载智能
  • 重新安装 intelliJ,但在安装过程中请确保不要选中“下载并安装 JetBrains 的 64 位 JRE(将与 64 位启动器一起使用)”

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

这使我的项目再次工作(在 32 位和 64 位版本中)。

回答by Juan Mendez

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.

就我而言,我只进入设置,搜索 JDK,单击 Java 编译器,然后我注意到缺少项目字节码版本。所以我只检查了 1.8,这是我的 Java 构建版本。对我来说就是这样。

enter image description here

在此处输入图片说明

回答by Hafiz umer

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

只需将jdk文件夹移动到intellij想要的文件夹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

然后更改想要的行中给出的 .gradle 文件夹中的值关闭项目然后重新启动

it works for me....

这个对我有用....

回答by Krishna

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.

我通过重命名 jre 和 jre64 文件夹以防止idea 使用它们并在idea.bat 文件中将JAVA_HOME 设置为我的其他JDK 1.8 安装来解决了这个问题。

回答by Dante

Add below in your gradle.propetries

在您的 gradle.propetries 中添加以下内容

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

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

for example:

例如:

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

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

还请添加以下内容的 gradle.properties:org.gradle.jvmargs=-Xmx512m