IntelliJ 构建错误上下文不匹配 [英] IntelliJ Build Error Context Mismatch

查看:26
本文介绍了IntelliJ 构建错误上下文不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

我已经按如下方式配置了 JDK 和 Android 工具:

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

推荐答案

我在调查类似问题时发现了这个问题,我解决了我的问题,所以也许我的经验会有所帮助.

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

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

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.

Wanted Java 版本恰好是 JRE 的系统范围安装,而不是我为项目配置的 JDK,也不是为 JAVA_HOME 设置的值,这让我非常怀疑(和困惑).重新排序我的路径导致它使用另一个不需要的"Java 版本,所以它显然是使用路径来选择要运行的内容,但不清楚为什么.我不能让 IntelliJ 的嵌入式 JRE 成为我的第一个路径,因为出于各种原因我需要它作为 JDK,所以我需要另一个解决方案.

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.

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

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.

原因原来是我在Run/Debug Configurations"对话框中定义了一个新的配置,并将build.gradle文件的完整路径放到了Gradle项目中: 字段,如下.(我通过单击字段右侧的省略号 (...) 按钮来完成此操作,但我也可以直接输入它.)

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

然而,我应该做的是遵循现有配置中的模式,其中 Gradle project: 被指定为注册项目",通过单击右侧的文件夹"图标字段,在下图中以绿色突出显示.在这种情况下,该字段的内容只是项目名称,并以略有不同的背景/前景色显示.(我无意中发现在这个名字上右击会替换为包含build.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.)

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

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.

这篇关于IntelliJ 构建错误上下文不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆