【问题标题】:Gradle: Could not initialize class org.codehaus.groovy.runtime.InvokerHelperGradle:无法初始化类 org.codehaus.groovy.runtime.InvokerHelper
【发布时间】:2020-09-30 13:43:57
【问题描述】:

我看到了这个 gradle 错误:“无法初始化类 org.codehaus.groovy.runtime.InvokerHelper”。我尝试了网上列出的多种方法来解决这个问题,但没有运气。 在调试过程中,我发现了奇怪的JVM版本。

安装了 Java 14 并且我在 bash_profile 的 JAVA_HOME 中设置了路径。但是,gradle 显示 JVM 13 版本。我不确定这是否会导致错误:无法初始化类 org.codehaus.groovy.runtime.InvokerHelper

我的java版本

java version "14.0.1" 2020-04-14
Java(TM) SE Runtime Environment (build 14.0.1+7)
Java HotSpot(TM) 64-Bit Server VM (build 14.0.1+7, mixed mode, sharing)

Gradle 版本,但不知道为什么 JVM 显示 13

Gradle 6.5
------------------------------------------------------------

Build time:   2020-06-02 20:46:21 UTC
Revision:     a27f41e4ae5e8a41ab9b19f8dd6d86d7b384dad4

Kotlin:       1.3.72
Groovy:       2.5.11
Ant:          Apache Ant(TM) version 1.10.7 compiled on September 1 2019
JVM:          **13.0.2 (Oracle Corporation 13.0.2+8)**
OS:           Mac OS X 10.14.6 x86_64

分级错误

npx react-native run-android
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 960 file(s) to forward-jetify. Using 4 workers...
info JS server already running.
info Launching emulator...
info Successfully launched emulator.
info Installing the app...

FAILURE: Build failed with an exception.

* What went wrong:
Could not initialize class org.codehaus.groovy.runtime.InvokerHelper

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 3s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081

FAILURE: Build failed with an exception.

* What went wrong:
Could not initialize class org.codehaus.groovy.runtime.InvokerHelper

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 3s

【问题讨论】:

  • --debug--stacktrace 添加到 Gradle 调用 cmd 以获取更多详细信息。

标签: react-native android-studio gradle react-native-android gradlew


【解决方案1】:

更改 gradle 的版本

编辑YOUR_PROJECT/android/gradle/wrapper/gradle-wrapper.properties中的文件并更改版本

来自:

distributionUrl=https://services.gradle.org/distributions/gradle-6.0.1-all.zip

到:

distributionUrl=https://services.gradle.org/distributions/gradle-6.4.1-all.zip

来源:https://github.com/gradle/gradle/issues/10248#issuecomment-633656326

【讨论】:

  • 我遇到了同样的问题,这对我有用。谢谢,巴勃罗!
  • 确实,您必须将其更改为系统中当前安装的版本。
  • 兄弟,你让我很开心,我遇到了这个错误并尝试了很多来解决,但没有任何效果这个解决方案对我有用。你应该得到的不仅仅是感谢
  • 这应该是“答案”。也适合我。
【解决方案2】:

您需要更改项目的 Gradle 版本。

官方文档中有提到:https://reactnative.dev/docs/environment-setup

"如果您使用的是最新版本的 Java 开发工具包,则需要更改项目的 Gradle 版本,以便它能够识别 JDK。您可以通过转到 {project root folder}\android 来完成\gradle\wrapper\gradle-wrapper.properties 并更改distributionUrl值以升级Gradle版本。您可以查看here the lastest releases of Gradle.

or see this image

【讨论】:

  • 您可以在答案中粘贴相应格式的文本,而不是发布官方文档的图像吗? (在需要时使用blockquotescode formatting
  • 图片只是为了显示文档中文本的写入位置。这样,读者就不会浪费时间了。
  • 然后你可以同时添加文本和图像。请记住,图像不可搜索,更难在移动设备上阅读,需要更多带宽,并且用户无法在其代码中复制和粘贴文本(例如作为评论)。
猜你喜欢
  • 2020-08-03
  • 2016-05-02
  • 2020-07-05
  • 2020-06-29
  • 1970-01-01
  • 2019-10-27
  • 2015-05-22
  • 2016-08-01
相关资源
最近更新 更多