赞
踩
Android Studio有时会报“Multiple Gradle deamons…”警告:
Multiple Gradle daemons might be spawned because the Gradle JDK and JAVA_HOME locations are different. Project 'yhpx' is using the following JDK location when running Gradle: 'D:/jdk11_x64' The system environment variable JAVA_HOME is: 'D:\.jdks\openjdk-20.0.2' If you dont need to use different paths (or if JAVA_HOME is undefined), you can avoid spawning multiple daemons by setting JAVA_HOME and the JDK location to the same path.
或者会提示:
The 'abc' project JDK configuration is now set through the #GRADLE_LOCAL_JAVA_HOME macro. This simplifies the JDK configuration experience and makes it more reliable. You can change this in the Gradle JDK settings.
这是由于Gradle使用的JDK和Android Studio使用的JDK不相同引起的。
点击“Learn more”后会打开链接:
https://developer.android.com/build/releases/past-releases/agp-8-2-0-release-notes#jdk-macro
这链接很可能打不开,可以使用以下链接:
也就是将android.com替换成google.cn即可。
可以看到具体的解决办法:
New macro to specify JDK path
#GRADLE_LOCAL_JAVA_HOME
is a new macro that you can use to specify the JDK path. This makes it safer and easier to specify the Java home path used for the Gradle daemon (background process) execution for your project. The path selection is stored in thejava.home
field in the.gradle/config.properties
file. Set this field through Gradle JDK settings in Android Studio: File (or Android Studio on macOS) > Settings > Build, Execution, Deployment > Build Tools > Gradle.New projects will use
#GRADLE_LOCAL_JAVA_HOME
by default. Existing projects will automatically be migrated to the new macro after a successful sync unless you're already using a macro like#JAVA_HOME
.The main benefits of the new macro are as follows:
- You can manually modify the JDK path to trigger sync without opening your project first.
- Fewer errors related to incompatible Gradle and project JDK versions since there is a single source of truth for your Gradle JDK selection.
或中文版:
用于指定 JDK 路径的新宏
#GRADLE_LOCAL_JAVA_HOME
是一个新宏,可用于指定 JDK 路径。这样,您就可以更安全、更轻松地指定用于为项目执行 Gradle 守护程序(后台进程)的 Java 主路径。路径选择存储在.gradle/config.properties
文件的java.home
字段中。通过 Android Studio 中的 Gradle JDK 设置来设置此字段:File(在 macOS 上则依次选择 Android Studio)> Settings > Build, Execution, Deployment > Build Tools > Gradle。新项目将默认使用
#GRADLE_LOCAL_JAVA_HOME
。成功同步后,现有项目将自动迁移到新宏,除非您已在使用类似#JAVA_HOME
的宏。新宏的主要优势如下:
- 您可以手动修改 JDK 路径以触发同步,而无需先打开项目。
- 与不兼容的 Gradle 和项目 JDK 版本相关的错误更少,因为 Gradle JDK 选择只有一个可信来源
按照说明,打开.gradle/config.properties,修改java.home字段即可。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。