React-native 在 gradle 时运行应用程序错误

问题描述 投票:0回答:1

我是反应原生新手,我开始制作我的第一个应用程序,一切都很好,直到我运行它,因为我收到此错误,如果有人可以帮助我,我会很感激,我完成了所有教程React-native 在它的页面中提供,所以我认为我安装正确。

info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 870 file(s) to forward-jetify. Using 12 workers...
info Starting JS server...
/bin/sh: adb: command not found
info Launching emulator...
error Failed to launch emulator. Reason: No emulators found as an output of `emulator -list-avds`.
warn Please launch an emulator manually or connect a device. Otherwise app may fail to launch.
info Installing the app...

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> SDK location not found. Define location with an ANDROID_SDK_ROOT environment variable or by setting the sdk.dir path in your project's local properties file at '/Users/fovu/Documents/AwesomeProject/android/local.properties'.

* 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 2s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> SDK location not found. Define location with an ANDROID_SDK_ROOT environment variable or by setting the sdk.dir path in your project's local properties file at '/Users/fovu/Documents/AwesomeProject/android/local.properties'.

* 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 2s

    at makeError (/Users/fovu/Documents/AwesomeProject/node_modules/execa/index.js:174:9)
    at /Users/fovu/Documents/AwesomeProject/node_modules/execa/index.js:278:16
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async runOnAllDevices (/Users/fovu/Documents/AwesomeProject/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:109:5)
    at async Command.handleAction (/Users/fovu/Documents/AwesomeProject/node_modules/@react-native-community/cli/build/index.js:192:9)
info Run CLI with --verbose flag for more details.
reactjs react-native
1个回答
0
投票

正如日志中提到的,它无法编译您的应用程序,因为找不到您的 Android SDK 的位置。

> SDK location not found. Define location with an ANDROID_SDK_ROOT environment variable or by setting the sdk.dir path in your project's local properties file at '/Users/fovu/Documents/AwesomeProject/android/local.properties'.

您的属性文件似乎指向了错误的 SDK 目录,您的 ANDROID_SDK_ROOT 路径指向了错误的目录,或者 ANDROID_SDK_ROOT 路径根本不存在。

我建议您阅读官方设置文档并遵循每个步骤:https://reactnative.dev/docs/environment-setup

附录

我在你的日志中看到react-native甚至看不到模拟器,因此这一行:

error Failed to launch emulator. Reason: No emulators found as an output of `emulator -list-avds`.

因此您需要手动启动模拟器,或者如果您没有 Android 模拟器,请安装一个。或者如果您愿意:您可以尝试将应用程序插入计算机并在手机上启用 USB 调试,以在手机上安装该应用程序。

© www.soinside.com 2019 - 2024. All rights reserved.