React Native adb reverse ENOENT

98

我正在尝试让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。

我执行adb devices时发现我的Android模拟器。

List of devices attached
192.168.56.101:5555 device

我尝试了Stack Overflow的这篇文章中提到的步骤,但仍然没有成功。

https://dev59.com/BlwZ5IYBdhLWcg3wYfdu#38536290
15个回答

3
如果没有任何一种解决方案有效,请尝试运行以下命令:source ~/.bash_profile&&react-native run-android。
在 package.json 文件的 scripts 字段下更新 Android 的配置为:"android": "source ~/.bash_profile&&react-native run-android"。
对于 MacOS 版本 Catalina 及以上版本,Android 的配置应为:"android": "source ~/.zshrc&&react-native run-android"。

我忘记重新启动/源终端了,这个对我有用。 - Nivethan

0
  1. 触摸~/.zshrc
  2. 打开~/.zshrc
  3. 添加 export ANDROID_SDK=/Users/<your_computer_name>/Library/Android/sdk export PATH=/Users/<your_computer_name>/Library/Android/sdk/platform-tools:$PATH
  4. 保存
  5. source ~/.zshrc
  6. 运行android

0

Mac OS Monterey或任何Mac版本

  1. nano ~/.zshrc
  2. export ANDROID_SDK_ROOT=/Users//Library/Android/sdk
  3. source ~/.zshrc
  4. echo $ANDROID_SDK_ROOT
  5. adb version

您的答案可以通过提供更多支持性信息来改进。请[编辑]以添加进一步的细节,例如引用或文档,以便其他人可以确认您的答案是否正确。您可以在帮助中心找到有关如何撰写好答案的更多信息。 - Community

0

我在 MacOS Monterrey 上使用 React Native 遇到了这个问题,按照下面的步骤解决了 https://github.com/facebook/react-native/issues/28712#issuecomment-617384353

  1. 打开终端
  2. 执行 touch ~/.bash_profile 创建一个文件
  3. 执行 open ~/.bash_profile 或者 vim ~/.bash_profile 编辑该文件
  4. 添加内容
export ANDROID_HOME=/Users/yourusername/Library/Android/sdk
export PATH=$ANDROID_HOME/tools:$PATH
export PATH=$ANDROID_HOME/platform-tools:$PATH
5. 如果执行`source ~/.bash_profile`没有起作用,那么 6. 在你的`package.json`文件中将`"android": "react-native run-android"`改为`"android": "source ~/.bash_profile&&react-native run-android"`,然后运行`yarn android`。

-1
在我的情况下,我使用Pop OS(Ubuntu),并且已经安装了Android Studio,所以我只需要
ln -s ~/Android/Sdk/platform-tools/adb /usr/bin/adb 

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接