You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native项目Android模拟器构建失败:InvokerHelper类初始化异常

解决Expo React Native Android构建错误:Could not initialize class org.codehaus.groovy.runtime.InvokerHelper

这个问题我帮不少开发者排查过,核心原因基本是Groovy版本与Gradle不兼容或者JDK版本不匹配,结合你的项目是Expo管理的RN 0.61.5版本,给你一步步的解决办法:

第一步:确认JDK版本是否正确

React Native 0.61.x系列要求使用JDK 8(1.8.x版本),如果安装了JDK 11或更高版本,就会触发这个Groovy初始化错误。你可以在终端运行以下命令查看当前JDK版本:

java -version

如果显示的是1.8.x以外的版本,建议切换到JDK 8(可以用jenv这类工具管理多版本JDK)。

第二步:检查Gradle版本配置

你的项目是RN 0.61.5,对应的Gradle wrapper版本应该是gradle-5.5.1-all.zip。打开项目根目录下的android/gradle/wrapper/gradle-wrapper.properties,确认distributionUrl的内容:

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

如果版本不对,修改后保存,然后删除android/.gradle文件夹,再重新执行构建。

第三步:清理项目缓存并重新安装依赖

缓存冲突也可能导致这类问题,按以下步骤操作:

  1. 删除项目根目录的node_modules和yarn.lock:
rm -rf node_modules yarn.lock
  1. 重新安装依赖:
yarn install
  1. 清理Android项目的构建缓存:
cd android && ./gradlew clean && cd ..
  1. 再次尝试构建:
yarn android

第四步:尝试禁用Jetifier(可选)

如果前面的步骤都没解决,可以试试禁用Jetifier,部分旧依赖可能和它存在兼容性问题:

yarn android --no-jetifier

你的项目错误日志:

info Running jetifier to migrate libraries to AndroidX. You can disable it using the "--no-jetifier" flag.
Jetifier found 1181 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 1s
    error Failed to install the app. Make sure you have the Android development environment set up: https://facebook.github.io/react-native/docs/getting-started.html#android-development-environment. 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 1s
    at checkExecSyncError (child_process.js:629:11)
    at execFileSync (child_process.js:647:13)
    at runOnAllDevices (/Users/pratik/Documents/dev_projects/ReactNativePOC/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:94:39)
    at process._tickCallback (internal/process/next_tick.js:68:7)
    error Command failed with exit code 1.
    info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

项目依赖:

"dependencies": {
  "@expo/vector-icons": "^10.2.0",
  "@react-native-community/masked-view": "^0.1.10",
  "@react-navigation/drawer": "^5.8.2",
  "@react-navigation/material-bottom-tabs": "^5.2.10",
  "@react-navigation/native": "^5.5.1",
  "@react-navigation/stack": "^5.5.1",
  "@types/react-native-snap-carousel": "^3.8.1",
  "@use-expo/font": "^2.0.0",
  "babel-plugin-module-resolver": "^4.0.0",
  "expo": "~37.0.3",
  "expo-font": "^8.1.1",
  "expo-updates": "~0.2.0",
  "intl": "^1.2.5",
  "react": "~16.9.0",
  "react-dom": "~16.9.0",
  "react-native": "~0.61.5",
  "react-native-gesture-handler": "^1.6.1",
  "react-native-paper": "^3.10.1",
  "react-native-reanimated": "^1.9.0",
  "react-native-safe-area-context": "^3.0.3",
  "react-native-screens": "^2.8.0",
  "react-native-snap-carousel": "^3.9.1",
  "react-native-unimodules": "~0.9.0",
  "react-native-web": "~0.11.7"
},
"devDependencies": {
  "@babel/core": "~7.9.0",
  "@types/react": "~16.9.23",
  "@types/react-native": "~0.61.23",
  "babel-preset-expo": "~8.1.0",
  "jest-expo": "~37.0.0",
  "typescript": "~3.8.3"
}

内容的提问来源于stack exchange,提问作者pratik agashe

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.08 10:37:27