React Native:Android 构建失败并出现异常 - 安装在模拟器上
Posted
技术标签:
【中文标题】React Native:Android 构建失败并出现异常 - 安装在模拟器上【英文标题】:React Native: Android build failed with exception - To install on emulator 【发布时间】: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"
,
【问题讨论】:
【参考方案1】:我发现了问题。和JDK版本有关。
我已经安装了最新版本的 JDK,它是 14。它不能很好地与 5.x 版本的 Gradle 一起使用。
所以我安装了 JDK 8,它适用于 5.x 版本的 Gradle。它奏效了!没想到是这个问题...
【讨论】:
以上是关于React Native:Android 构建失败并出现异常 - 安装在模拟器上的主要内容,如果未能解决你的问题,请参考以下文章
React-Native Android 构建失败 - 无法找到请求目标的有效认证路径
Android Studio React Native 构建失败
React Native:Android 构建失败并出现异常 - 安装在模拟器上
修复 React-Native run-android 上的构建失败
React-native 项目构建失败:找不到 com.android.tools.lint:lint-gradle:26.1.0
React Native 和 Android Studio:应用无法构建。错误:命令失败:gradlew.bat app:installDebug -PreactNativeDevServerPort