React-native:无法初始化类org.codehaus.groovy.reflection.ReflectionCache

我按照https://reactnative.dev/docs/environment-setup 的说明进行了 React-native 设置

项目已成功创建。

Android 手机也使用 USB 连接,但是当我尝试使用命令在手机上安装应用程序时 -

npx react-native run-android
npx react-native run-android

发生以下错误并且 BUILD FAILED

what went wrong

Could not initialize class org.codehaus.groovy.reflection.ReflectionCache

错误:

Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7

我正在使用Powershell执行命令。

回答

答案很简单,我在发布这个问题大约一周后得到了它。

您只需要更新到最新的 gradle 版本。

  1. 转到项目文件夹中的android > gradle > gradle-wrapper.properties文件。

gradle-wrapper.properties文件中,使用最新版本的 gradle更改以下行:

distributionUrl=https://services.gradle.org/distributions/gradle-6.7.1-all.zip
  1. 只需将版本号 6.7.1 更改为最新号即可。

再次运行命令以构建您的应用程序:

它解决了我的问题,并且使用 USB 在 Android 手机上安装了 React-native 应用程序。


以上是React-native:无法初始化类org.codehaus.groovy.reflection.ReflectionCache的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>