React Native adb reverse ENOENT

2019-01-18 03:46发布

问题:

I am trying to get React-Native to work with Android V4.2.2 (Genymotion) but I am unable to test the app on the Emulator. When I ran react-native run-android, I get this error Could not run adb reverse: spawnSync

Here is a log

JS server already running.
Running /User/Pan/Library/Android/sdk/platform-tools/adb reverse tcp:8081 tcp:8081
Could not run adb reverse: spawnSync /User/Pan/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 '/User/Pan/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

NOTE: In the log it saids SDK directory does not exist, I have double check that I do have the SDK installed in that directory.

I found my android emulator when executing adb devices

List of devices attached
192.168.56.101:5555 device

I have tried the following steps from Stack Overflow post, but still no luck https://stackoverflow.com/a/38536290/4540216

回答1:

I got the same issue. I updated my ANDROID_HOME env variable again it worked for me.

Follow this React-native android-setup documentation

ex:

export ANDROID_HOME=~/Library/Android/sdk


回答2:

I also got the same issue. And I updated my ANDROID_HOME env variable again in same cmd and it was worked fine.

> export ANDROID_HOME=~/Android/Sdk 
> export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

good luck



回答3:

First I have setup the path in .bash_profile like this

export PATH="~/Library/Android/sdk/platform-tools":$PATH
export ANDROID_HOME="~/Library/Android/sdk/platform-tools"

But it does not resolve my problem.

For me by adding following npm script in package.json under script tag worked like charm on Mac.

"android-dev": "adb reverse tcp:8081 tcp:8081 && react-native run-android"

Then I am simply running npm run android-dev and it's all set. Make sure that in your app setting Live reload is enabled already, in this way I can worked on development server on my mobile and see the coding changes immediately in app.