【问题标题】:React Native: Android build failed with exception - To install on emulatorReact Native:Android 构建失败并出现异常 - 安装在模拟器上
【发布时间】:2020-10-19 15:38:05
【问题描述】:

这是我的第一个 react 原生应用。我能够在 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"
  },

【问题讨论】:

    标签: android react-native build.gradle


    【解决方案1】:

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

    我已经安装了最新版本的 JDK,它是 14。它不能很好地与 5.x 版本的 Gradle 一起使用。

    所以我安装了 JDK 8,它适用于 5.x 版本的 Gradle。它奏效了!没想到是这个问题...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-22
      • 1970-01-01
      • 2020-11-07
      • 1970-01-01
      • 1970-01-01
      • 2021-08-23
      • 1970-01-01
      • 2023-03-22
      相关资源
      最近更新 更多