React Native CLI Android 安装错误

React Native CLI Android installation error

我是 React Native 的新手,我试图按照有关如何使用 React Native CLI 启动 React Native 应用程序的示例进行操作,但我的 CMD 中一直出现此错误。

C:\React Native Workspace\RN-CLI\FirstCli>npx react-native run-android
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 863 file(s) to forward-jetify. Using 12 workers...
info Starting JS server...
'adb' is not recognized as an internal or external command,
operable program or batch file.
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...
Starting a Gradle Daemon (subsequent builds will be faster)

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 'C:\React Native Workspace\RN-CLI\FirstCli\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 10s

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.bat 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 'C:\React Native Workspace\RN-CLI\FirstCli\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 10s

    at makeError (C:\React Native Workspace\RN-CLI\FirstCli\node_modules\execa\index.js:174:9)
    at C:\React Native Workspace\RN-CLI\FirstCli\node_modules\execa\index.js:278:16
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async runOnAllDevices (C:\React Native Workspace\RN-CLI\FirstCli\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:109:5)
    at async Command.handleAction (C:\React Native Workspace\RN-CLI\FirstCli\node_modules\@react-native-community\cli\build\index.js:192:9)
info Run CLI with --verbose flag for more details.

我需要帮助解决这些问题。

假设您已经安装了 Android SDK,您需要在 Android 项目 your-react-native-project-android/ 的根目录下创建一个名为 local.properties 的文件,您应该如果您使用 git.

,也将其添加到 .git 忽略

该文件必须指明 SDK 在您计算机上的路径,例如 macOS

local.properties

## This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
#Tue Oct 26 14:02:40 CEST 2021
sdk.dir=/Users/username/Library/Android/sdk

如果您从未安装过SDK,则需要启动here