先附上错误信息:
2021-09-17 10:32:44,355 [1924382] INFO - System.util.ExternalSystemUtil - External project [E:/space-persional/git/oldmoon-frame] resolution task started
2021-09-17 10:32:44,438 [1924465] INFO - s.plugins.gradle.GradleManager - Instructing gradle to use java from C:/Program Files/Java/jdk1.8.0_221
2021-09-17 10:32:44,441 [1924468] INFO - s.plugins.gradle.GradleManager - Instructing gradle to use java from C:/Program Files/Java/jdk1.8.0_221
2021-09-17 10:32:44,445 [1924472] INFO - oject.common.GradleInitScripts - init script file sync.studio.tooling contents "initscript {\n dependencies {\n classpath files(['D:\\\\Program Files\\\\JetBrains\\\\IntelliJ IDEA 2020.3.2\\\\plugins\\\\android\\\\lib\\\\android.jar', 'D:\\\\Program Files\\\\JetBrains\\\\IntelliJ IDEA 2020.3.2\\\\plugins\\\\android\\\\lib\\\\android.jar', 'D:\\\\Program Files\\\\JetBrains\\\\IntelliJ IDEA 2020.3.2\\\\lib\\\\kotlin-stdlib-1.4.0.jar'])\n }\n}\nallprojects {\n apply plugin: com.android.ide.gradle.model.builder.AndroidStudioToolingPlugin\n}\n"
2021-09-17 10:32:44,449 [1924476] INFO - xecution.GradleExecutionHelper - Passing command-line args to Gradle Tooling API: -Didea.sync.active=true -Didea.resolveSourceSetDependencies=true -Porg.gradle.kotlin.dsl.provider.cid=3206336083900 --init-script C:\Users\Administrator\AppData\Local\Temp\sync.studio.tooling6.gradle -Djava.awt.headless=true --stacktrace -Pandroid.injected.build.model.only=true -Pandroid.injected.build.model.only.advanced=true -Pandroid.injected.invoked.from.ide=true -Pandroid.injected.build.model.only.versioned=3 -Pandroid.injected.studio.version=10.4.0.203.7148.57 -Pandroid.injected.build.model.disable.src.download=true -Pidea.gradle.do.not.build.tasks=false --init-script C:\Users\Administrator\AppData\Local\Temp\ijinit.gradle
2021-09-17 10:32:45,798 [1925825] INFO - .project.GradleProjectResolver - Gradle project resolve error
org.gradle.tooling.GradleConnectionException: Could not run phased build action using connection to Gradle installation 'D:\Program Files\gradle-6.6'.
at org.gradle.tooling.internal.consumer.ExceptionTransformer.transform(ExceptionTransformer.java:55)
at org.gradle.tooling.internal.consumer.ExceptionTransformer.transform(ExceptionTransformer.java:29)
at org.gradle.tooling.internal.consumer.ResultHandlerAdapter.onFailure(ResultHandlerAdapter.java:43)
at org.gradle.tooling.internal.consumer.async.DefaultAsyncConsumerActionExecutor$1$1.run(DefaultAsyncConsumerActionExecutor.java:69)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: org.gradle.launcher.daemon.client.DaemonConnectionException: 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.8.0_221,daemonRegistryDir=D:\Program Files\gradle-6.6\resporitory\daemon,pid=7056,idleTimeout=null,priority=NORMAL,daemonOpts=-XX:MaxMetaspaceSize=256m,-XX:+HeapDumpOnOutOfMemoryError,-Xms256m,-Xmx512m,-Dfile.encoding=GBK,-Duser.country=CN,-Duser.language=zh,-Duser.variant]
Actual: DefaultDaemonContext[uid=03885807-b0b5-4b78-bdd1-9498b178eefd,javaHome=C:\Program Files\Java\jdk1.8.0_221\jre,daemonRegistryDir=D:\Program Files\gradle-6.6\resporitory\daemon,pid=3908,idleTimeout=10800000,priority=NORMAL,daemonOpts=-XX:MaxMetaspaceSize=256m,-XX:+HeapDumpOnOutOfMemoryError,-Xms256m,-Xmx512m,-Dfile.encoding=GBK,-Duser.country=CN,-Duser.language=zh,-Duser.variant]
at org.gradle.launcher.daemon.client.DefaultDaemonConnector.connectToDaemonWithId(DefaultDaemonConnector.java:253)
at org.gradle.launcher.daemon.client.DefaultDaemonConnector.doStartDaemon(DefaultDaemonConnector.java:222)
at org.gradle.launcher.daemon.client.DefaultDaemonConnector.startDaemon(DefaultDaemonConnector.java:211)
at org.gradle.launcher.daemon.client.DefaultDaemonConnector.connect(DefaultDaemonConnector.java:133)
at org.gradle.launcher.daemon.client.DaemonClient.execute(DaemonClient.java:145)
at org.gradle.launcher.daemon.client.DaemonClient.execute(DaemonClient.java:99)
at org.gradle.tooling.internal.provider.DaemonBuildActionExecuter.execute(DaemonBuildActionExecuter.java:48)
at org.gradle.tooling.internal.provider.DaemonBuildActionExecuter.execute(DaemonBuildActionExecuter.java:32)
at org.gradle.tooling.internal.provider.LoggingBridgingBuildActionExecuter.execute(LoggingBridgingBuildActionExecuter.java:60)
at org.gradle.tooling.internal.provider.LoggingBridgingBuildActionExecuter.execute(LoggingBridgingBuildActionExecuter.java:38)
at org.gradle.tooling.internal.provider.ProviderConnection.run(ProviderConnection.java:218)
at org.gradle.tooling.internal.provider.ProviderConnection.runPhasedAction(ProviderConnection.java:179)
at org.gradle.tooling.internal.provider.DefaultConnection.run(DefaultConnection.java:245)
at org.gradle.tooling.internal.consumer.connection.PhasedActionAwareConsumerConnection.run(PhasedActionAwareConsumerConnection.java:56)
at org.gradle.tooling.internal.consumer.connection.ParameterValidatingConsumerConnection.run(ParameterValidatingConsumerConnection.java:62)
at org.gradle.tooling.internal.consumer.DefaultPhasedBuildActionExecuter$1.run(DefaultPhasedBuildActionExecuter.java:78)
at org.gradle.tooling.internal.consumer.DefaultPhasedBuildActionExecuter$1.run(DefaultPhasedBuildActionExecuter.java:70)
at org.gradle.tooling.internal.consumer.connection.LazyConsumerActionExecutor.run(LazyConsumerActionExecutor.java:130)
at org.gradle.tooling.internal.consumer.connection.CancellableConsumerActionExecutor.run(CancellableConsumerActionExecutor.java:45)
at org.gradle.tooling.internal.consumer.connection.ProgressLoggingConsumerActionExecutor.run(ProgressLoggingConsumerActionExecutor.java:61)
at org.gradle.tooling.internal.consumer.connection.RethrowingErrorsConsumerActionExecutor.run(RethrowingErrorsConsumerActionExecutor.java:38)
at org.gradle.tooling.internal.consumer.async.DefaultAsyncConsumerActionExecutor$1$1.run(DefaultAsyncConsumerActionExecutor.java:67)
... 6 more
-
这个错误信息是从IDEA的日志中看到的,因为如果遇到这个错,IDEA控制台不会体现任何有用的错误日志,所以就只能看IDEA的日志了。 -
出现这个错误时,你的Gradle项目什么都干不了,就连clear 都不行,执行main 方法也不行。
解决过程:
通过看上边的日志,我觉得最根本的错误在与中间的几行日志:
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.8.0_221,daemonRegistryDir=D:\Program Files\gradle-6.6\resporitory\daemon,pid=7056,idleTimeout=null,priority=NORMAL,daemonOpts=-XX:MaxMetaspaceSize=256m,-XX:+HeapDumpOnOutOfMemoryError,-Xms256m,-Xmx512m,-Dfile.encoding=GBK,-Duser.country=CN,-Duser.language=zh,-Duser.variant]
Actual: DefaultDaemonContext[uid=03885807-b0b5-4b78-bdd1-9498b178eefd,javaHome=C:\Program Files\Java\jdk1.8.0_221\jre,daemonRegistryDir=D:\Program Files\gradle-6.6\resporitory\daemon,pid=3908,idleTimeout=10800000,priority=NORMAL,daemonOpts=-XX:MaxMetaspaceSize=256m,-XX:+HeapDumpOnOutOfMemoryError,-Xms256m,-Xmx512m,-Dfile.encoding=GBK,-Duser.country=CN,-Duser.language=zh,-Duser.variant]
It won’t be possible to reconnect to this daemon. Context mismatch:
Java home is different.
且上面这两行,类似明确告诉你错误的语句更是重点,在Wanted (期望)和Actual (事实)中,确实可以看到javaHome 不一样,多了一层/jre 。
BUT、但是,通过各种配置的检查:IDEA的JDK配置、JAVA环境变量配置、Gradle自身配置、IDEA的Gradle配置等等,均没有发现任何问题。
此时已经过去半天的时间,其中也尽力过几次百度的过程,没有发现特别有价值的线索~
但是我不死心,我相信百度,我又给百度最后一次机会,终于在一篇文章里。。特别简短的文章。。发现了真理!!!!这次百度我仅仅用了四个单词:Java home is different !!
问题原因
参考文章:https://www.cnblogs.com/lishuaiqi/p/13447834.html
简而言之就是JDK 中自带的一个tools.jar ,他应该在/jdk/lib/ 目录下,而/jdk/jre/lib/ 目录下应该是没有的,经过某些不为人知的过程,/jdk/jre/lib/ 底下也有了tools.jar 。。。。。所以导致Gradle 认错了javahome 。。。。
我回想起来,确实在解决某次bug 的时候,把tools.jar 这个包移到了jre下,所以我就按照此文章的说法,把jre下的tools.jar 包干掉了。。。然后重启IDEA就可以了。。。。
只能说这个bug确实太让人想不到了。。。原文的作者不知道是怎么发现的这个问题原因。。。。佩服!!!
这同时也说明,不同人的思路确实是不一样,Gradle开发人员大概打死也没想到会有人去动tools.jar 这个包吧。谁对谁错咱就让时间来证明吧~
也有可能时间会让人忘了,这个错误曾经也出现过~~
PS:标题中列出了我认为比较容易被搜索的关键字,便于遇到这个错误的人看到这篇文章,有其他推荐的关键字欢迎评论~
|