Failed to complete Gradle execution (new project)

2019-01-15 09:53发布

问题:

I downloaded Android Studio version [build 135.1653844] and created a new project. I am getting an error:

Failed to complete Gradle execution.
Cause:
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\Java\jdk1.6.0_45,daemonRegistryDir=C:\Users\gargn\.gradle\daemon,pid=1000,idleTimeout=null,daemonOpts=-XX:MaxPermSize=256m,-XX:+HeapDumpOnOutOfMemoryError,-Xmx1024m,-Dfile.encoding=windows-1252,-Duser.country=US,-Duser.language=en,-Duser.variant]
Actual: DefaultDaemonContext[uid=9a6c3945-1d55-46d7-897b-4ed84a5707bb,javaHome=C:\Program Files\Java\jdk1.6.0_45\jre,daemonRegistryDir=C:\Users\gargn\.gradle\daemon,pid=1664,idleTimeout=10800000,daemonOpts=-XX:MaxPermSize=256m,-XX:+HeapDumpOnOutOfMemoryError,-Xmx1024m,-Dfile.encoding=windows-1252,-Duser.country=US,-Duser.language=en,-Duser.variant]

My Java home is set to C:\Program Files\Java\jdk1.6.0_45 and I could not find any setting where I am using the jre path. I searched in all text files and could not find jre path as shown in the error above.

回答1:

Though I did not find the root cause where the different javaHomes have been taken from, at least I found a workaround that worked for me:

Try setting the following in your gradle.properties (either in %USERPROFILE%\.gradle\ or in your project build dir):

org.gradle.java.home=C:\Program Files\Java\jdk1.6.0_45\jre


回答2:

I deleted the jre from the installation file of inttellij, but when I tried to run intellij, i said that I tried to run a 32bit version of intellij, but no jre for 32bit was found, then I when to the intellij installation directory and run a 64bit version, and the problem was solved.



回答3:

Another answer for people looking for a solution:

In my case, I did not have any 32 bit JVMs installed, so I ran IntelliJ in 64 bit mode instead, and everything worked fine after I set my IDEA_JVM_64 environment variable.



回答4:

Bit Late,But will be helpful for someone,

For me the problem was solved by uninstalling all jdks and installing only one and setting JAVA_HOME for that jdk in my case

JAVA_HOME
C:\Program Files\Java\jdk1.7.0_40

Thats All



回答5:

This error appear most likely downloading applications (such as Oracle, Application servers...) that include java version or installing another JDK/JRE.

I managed to solve the this problem by deleting/renaming all JDK/JRE and forders and only keep one and only one JDK folder and contains JRE folder inside.

also I put the JDK path into JAVA_HOME and path vatiables and remove any other JDK/JRE paths from the environment variables.

After that reset the JDK home in your IDE.

Regards, Mohammed Kharma



回答6:

I managed to solve this problem by renaming Info.plist and version.plist to Info.plist.old and version.plist.old in /Applications/IntelliJ IDEA.app/Contents/jre/jdk/Contents folder on Mac.

Executed

mv Info.plist Info.plist.old | mv version.plist version.plist.old

in folder mentioned above. Then I just run Intellij and things were working fine. Probably, it would be possible to fix this by renaming only one of these files but I haven't tested it. After fixing it I haven't rename files back to Info.plist and version.plist. Should I?

After this fix, I also created idea.properties file in ~/Library/Preferences/IntelliJIdea2016.2 and added line gradle.java.home=$(/usr/libexec/java_home)