React Native:Android构建因异常而失败-要安装在模拟器上

时间:2020-06-29 13:00:05

标签: android react-native build.gradle

这是我的第一个反应本机应用程序。我能够在iOS模拟器上成功运行此程序,但是使用Android emulator时,我遇到了问题。

我运行了以下命令yarn android。它打开了我的android emulator,但是构建失败,并出现异常。该应用由博览会管理。早期的仿真器无法打开已修复的路径。

这是详细的错误:

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"
  },

1 个答案:

答案 0 :(得分:0)

我发现了问题。它与JDK版本有关。

我已经安装了JDK的最新版本14。它在Gradle的5.x版本中无法正常工作。

因此,我安装了JDK 8,该版本可与Gradle的5.x版本一起使用。而且有效!没想到这就是问题所在...