Faced with `org.gradle.api.ProjectConfigurationException` error on my `gradle build`(在我的“gradle build中遇到“org.gradle.api.ProjectConfigurationException错误)
问题描述
以下是 Gradle 规格:
Below are the Gradle specs:
- Gradle 4.6
- Android Gradle 插件 3.1.1
- 启用并行执行
- 启用缓存
从 gradle.com 阅读有关 gradle 构建优化的信息后,我下载了最新的稳定 JVM (9.0.4) 并在 Android Studio 中交换了 JVM (Java 8)(默认 - 嵌入式).完成此操作并执行 gradle build
后,我在终端中收到了 java.lang.NullPointerException(无错误消息)
.下面是完整的堆栈跟踪.
After reading about gradle build optimization from gradle.com, I downloaded the latest stable JVM (9.0.4) and swapped the JVM (Java 8) in Android Studio (default - embedded). After doing this and executing gradle build
, I got the java.lang.NullPointerException (no error message)
in my terminal. Below is the complete stacktrace.
因此,我切换回 Android Studio 附带的嵌入式 JVM,但错误并没有消失.我无法确定性地评估此错误的原因.我试图清理,重建,使缓存无效,实际上完全删除了 .gradle
文件,没有任何效果.此外,我删除了整个项目目录,并创建了一个新目录,通过 git clone
从我的应用程序存储库中恢复内容(安全状态 - 在所有这些优化更改之前),即使这样也不起作用.
Consequently, I switched back to the embedded JVM that came with Android Studio but the error didn't go away. I am unable to deterministically evaluate the cause for this error. I tried to clean, rebuild, invalidate cache, in fact, completely deleted the .gradle
file, nothing worked. Further, I deleted the entire project directory, and made a new directory restoring the contents via git clone
from my app repository (safe state - before all those optimization changes), even this did not work.
以下是错误的完整堆栈跟踪.
Below is the complete stacktrace of the error.
推荐答案
我能够通过读取 gradle 守护进程的输出日志来解决这个问题,下面是帮助我修复它的相关行.
I was able to solve this issue by reading the output log from the gradle daemon and below is the relevant line that helped me fix it.
14:52:50.575 [INFO] [org.gradle.launcher.daemon.server.Daemon] start()调用守护进程 -DefaultDaemonContext[uid=03e55abd-dc5a-42c5-bc7f-fc25f6a78bcb,javaHome=/Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home,daemonRegistryDir=/Users/user_name/.gradle/daemon,pid=16809,idleTimeout=10800000,daemonOpts=-Xmx1536m,-Dfile.encoding=UTF-8,-Duser.country=US,-Duser.language=en,-Duser.variant]
14:52:50.575 [INFO] [org.gradle.launcher.daemon.server.Daemon] start() called on daemon - DefaultDaemonContext[uid=03e55abd-dc5a-42c5-bc7f-fc25f6a78bcb,javaHome=/Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home,daemonRegistryDir=/Users/user_name/.gradle/daemon,pid=16809,idleTimeout=10800000,daemonOpts=-Xmx1536m,-Dfile.encoding=UTF-8,-Duser.country=US,-Duser.language=en,-Duser.variant]
因此,要点是 gradle 设置和 Android Studio 设置彼此独立工作.当 org.gradle.java.home
未在属性中显式设置时,Gradle 在启动守护程序并进行构建时依赖 JAVA_HOME 环境变量.
So, the gist is that the gradle settings and Android Studio settings work independent of each other. Gradle relies on the JAVA_HOME env var while starting up a daemon and making your build, when org.gradle.java.home
isn't explicitly set in properties.
因此,当回滚到不同的 JVM 时,请确保将 JAVA_HOME 环境变量设置为特定的 JVM(如果您在所有应用程序中使用相同的 JVM)或在 gradle 中设置如下所示的守护程序特定设置.properties
文件在项目级别可见:
Therefore, when rolling back to a different JVM, make sure to set the JAVA_HOME env var to that specific JVM (if you use the same JVM across all your applications) or set daemon specific setting like below in your gradle.properties
file visible at the project level :
请注意,以上是我的路径,我使用的是 Mac.在其他平台上可能会有所不同.
这篇关于在我的“gradle build"中遇到“org.gradle.api.ProjectConfigurationException"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!