我正在尝试让 React-Native 与 Android V4.2.2 (Genymotion)
一起工作,但我无法在模拟器上测试应用程序。当我运行 react-native run-android
时,我收到此错误 Could not run adb reverse: spawnSync
这是一个日志
JS server already running.
Running ~/Library/Android/sdk/platform-tools/adb reverse tcp:8081 tcp:8081
Could not run adb reverse: spawnSync ~/Library/Android/sdk/platform-tools/adb ENOENT
Building and installing the app on the device (cd android && ./gradlew installDebug...
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> The SDK directory '~/Library/Android/sdk' does not exist.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 3.785 secs
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/android-setup.html
注意:在日志中说 SDK 目录不存在,我仔细检查了该目录中是否安装了 SDK。
执行时发现我的android模拟器 adb devices
List of devices attached
192.168.56.101:5555 device
我已经尝试了 Stack Overflow 帖子中的以下步骤,但仍然没有运气 https://stackoverflow.com/a/38536290/4540216
原文由 XPLOT1ON 发布,翻译遵循 CC BY-SA 4.0 许可协议
我遇到了同样的问题。我再次更新了我的 ANDROID_HOME 环境变量,它对我有用。
遵循这个 React-native android-setup 文档
前任:
视窗:
macOS Mojave 及更早版本或 bash 用户:
1 - 打开您的 bash 个人资料:
将此添加到您的 bash_profile:
保存并关闭
编译您的更改
对于 macOS Catalina 和 zsh 用户:
从 macOS Catalina 开始,您的 Mac 使用 zsh 作为默认登录 shell 和交互式 shell。您也可以在早期版本的 macOS 中将 zsh 设为默认值。
在您的 Mac 上:
打开你的 .zshrc 文件:
如果.zshrc 文件不存在,您需要使用
touch
创建一个并打开。将此添加到您的 .zshrc 文件中
保存并关闭
编译您的更改
编辑:更新了 macOS Catalina 和 zsh 用户的答案。