npx react-native run-android 不会启动模拟器,并且如果模拟器正在运行也不会运行

Moh*_*hde 9 macos android android-emulator react-native

我已经使用react-native 0.63创建了一个新项目\n当我在ios模拟器上运行时一切正常\n但是当尝试在android上运行它时,它不起作用并给我这个错误

\n
FAILURE: Build failed with an exception.\n\n* What went wrong:\nCould not determine the dependencies of task \':app:installDebug\'.\n> 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 \'/Volumes/SSD2/developer/MyProject/AwesomeProject/android/local.properties\'.\n\n* Try:\nRun 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.\n\n* Get more help at https://help.gradle.org\n\nBUILD FAILED in 2s\n\nerror Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details.\nError: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081\n
Run Code Online (Sandbox Code Playgroud)\n

我安装反应本机像\n React-Native 设置

\n

这是我的本地反应医生的输出

\n
\xe2\x9c\x93 Node.js\n \xe2\x9c\x93 npm\n \xe2\x9c\x93 Watchman - Used for watching changes in the filesystem when in development mode\n\nAndroid\n \xe2\x9c\x93 JDK\n \xe2\x9c\x93 Android Studio - Required for building and installing your app on Android\n \xe2\x9c\x96 Android SDK - Required for building and installing your app on Android\n   - Versions found: N/A\n   - Version supported: 29.0.2\n \xe2\x9c\x96 ANDROID_HOME\n\niOS\n \xe2\x9c\x93 Xcode - Required for building and installing your app on iOS\n \xe2\x9c\x93 CocoaPods - Required for installing iOS dependencies\n \xe2\x9c\x93 ios-deploy - Required for installing your app on a physical device with the CLI\n\nErrors:   2\nWarnings: 0\n
Run Code Online (Sandbox Code Playgroud)\n

如果我运行 npx react-native start 那么应用程序可以从 android studio 顺利运行。

\n

编辑\n如果我从终端源 .bash_profile 运行项目

\n

模拟器启动但项目未运行

\n
"--no-jetifier" flag.\nJetifier found 5194 file(s) to forward-jetify. Using 12 workers...\ninfo JS server already running.\ninfo Installing the app...\nenv: sh\\r: No such file or directory\n\nerror Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details.\nError: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081\nenv: sh\\r: No such file or directory\n
Run Code Online (Sandbox Code Playgroud)\n

Jac*_*ack 10

看起来您需要设置 ANDROID_HOME 环境变量。

\n

将以下行添加到 $HOME/.bash_profile 或 $HOME/.bashrc (如果您使用 zsh,则使用 ~/.zprofile 或 ~/.zshrc)配置文件:

\n
export ANDROID_HOME=$HOME/Library/Android/sdk\nexport PATH=$PATH:$ANDROID_HOME/emulator\nexport PATH=$PATH:$ANDROID_HOME/tools\nexport PATH=$PATH:$ANDROID_HOME/tools/bin\nexport PATH=$PATH:$ANDROID_HOME/platform-tools\n
Run Code Online (Sandbox Code Playgroud)\n

键入 source $HOME/.bash_profile for bash 或 source $HOME/.zprofile 将配置加载到当前 shell 中。通过运行 echo $ANDROID_HOME 验证 ANDROID_HOME 是否已设置,并且通过运行 echo $PATH 已将适当的目录添加到您的路径中。

\n

请确保您使用正确的 Android SDK 路径。您可以在 Android Studio“首选项”对话框中的外观和行为 \xe2\x86\x92 系统设置 \xe2\x86\x92 Android SDK 下找到 SDK 的实际位置。

\n

参考:

\n\n