Gradle:无法初始化类 org.codehaus.groovy.runtime.InvokerHelper

rea*_*ive 11 gradle gradlew android-studio react-native react-native-android

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

安装了 Java 14,我在 bash_profile 中的 JAVA_HOME 中设置了路径。但是,gradle 显示的是 JVM 13 版本。我不确定这是否会导致错误:Could not initialize class 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)
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

摇篮错误

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
Run Code Online (Sandbox Code Playgroud)

小智 60

更改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


Dee*_*tal 6

Gradle 对于 Java 版本非常具体。我们需要检查兼容性矩阵并设置gradle版本需要的java版本。

https://docs.gradle.org/current/userguide/compatibility.html

与启动 gradle 守护进程相关的问题主要是因为 JAVA。我们不需要升级或降级gradle版本。无需更改设置文件。