70

I try to run react-native app on genymotion android emulator on my mac. When I write react-native run-android It gets

Running /usr/local/opt/android-sdk/platform-tools/adb reverse tcp:8081 tcp:8081
error: closed
Could not run adb reverse: Command failed: /usr/local/opt/android-sdk/platform-tools/adb reverse tcp:8081 tcp:8081
Building and installing the app on the device (cd android && ./gradlew installDebug...
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
MacBook-Pro-MacBook:ART-CarefulPeople macbook$ 

Then I've tried:

  1. react-native start
  2. react-native run-android

The same result.

Then I've tried:

  1. react-native bundle --entry-file index.android.js --platform android --bundle-output android/app/src/main/assets/index.android.bundle

  2. curl "http://localhost:8081/index.android.bundle?platform=android" -o "android/app/src/main/assets/index.android.bundle"

  3. react-native run-android

The same result.

I've tried just adb reverse tcp:8081 tcp:8081 and it says error: closed

When I try to run app on android-sdk emulator it gets the same error above but without error: closed.

From android studio I can run this app and it works on genymotion. Tell me please what should I do to run my app on android emulator?

alborozd
  • 860
  • 1
  • 6
  • 11
  • 6
    `adb revese` only works on Android 5.0+ devices – Xeijp Jul 26 '16 at 02:17
  • 1
    Yes. I don't know what was that. I just recreated project and everything works fine. – alborozd Jul 26 '16 at 14:49
  • I believe that if your Android phone (assuming you have one) is hooked up to your computer it may be trying to install it on that device. If it is plugged in I would recommend unplugging it, making sure your emulator is running and then trying the `react-native run-android` command again. – jasonmerino Jul 29 '16 at 18:28
  • This might help [How to run react native on android emulator](https://www.youtube.com/watch?v=8ejuHsaXiwU) – InfiniteStack Dec 28 '22 at 02:48

13 Answers13

64

I had a similar problem, and after spending so much time and lots of searching about this issue the only trick worked for me:

  1. Please Install the Required SDKs as shown in this figure

Configure Required SDKs Configure Required SDKs

  1. If You have already installed it, so you must have to update the following SDKs:
    • Android SDK Tool (update it to latest version)
    • Android SDK Platform-tools (update it to latest version)
    • Android SDK Build-tools (update it to latest version)
    • Android Support Repository under Extra folder (update it to latest version)
  2. You Must have at least Installed the Same version Android API as the installed Android SDK Build-tools & Android SDK Platform-tools version as shown in the Configure Required SDKs figure above.

Note: Local Maven repository for Support Libraries which is listed as the SDK requirement in the official docs of React-native is now named as Android Support Repository in the SDK Manager .

Rizwan Jamal
  • 1,254
  • 10
  • 13
59

On macOs I manage to fix this by adding:

export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools

to ~/.zsh_profile file.

and than type to your terminal

source $HOME/.zsh_profile

The issue was caused by using iTerm2 shell so it's required to edit its own config instead of default $HOME/.bash_profile as described in the official documentation https://reactnative.dev/docs/environment-setup

32

React Native (On Mac OS Big SUR)

i was stuck here. But updating the environment settings for Android studio did the trick.

nano ~/.zshrc

and paste

export ANDROID_SDK_ROOT=$HOME/Library/Android/sdk
export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/emulator:$PATH
export PATH=$PATH:$ANDROID_HOME/tools:$PATH
export PATH=$PATH:$ANDROID_HOME/tools/bin:$PATH
export PATH=$PATH:$ANDROID_HOME/platform-tools:$PATH
export JAVA_HOME=$(/usr/libexec/java_home)

control + o to save then enter then control + x to exit

then do source ~/.zshrc to compile

kill the runnig terminals and run npx react-native run-android

Aayush Bhattacharya
  • 1,628
  • 18
  • 17
16

You can also try use "doctor" command. It will fix most cases.

npx @react-native-community/cli doctor
Cihan Yakar
  • 2,402
  • 28
  • 30
13

I had similar issue running emulator from android studio everytime, or on a physical device. Instead, you can quickly run android emulator from command line,

android avd

Once the emulator is running, you can check with adb devices if the emulator shows up. Then you can simply use react-native run-android to run the app on the emulator.

Make sure you've platform tools installed to be able to use adb. Or you can use

brew install android-platform-tools
scazzy
  • 950
  • 2
  • 8
  • 20
  • 5
    don't brew install the commandline tools, they are deprecated. Use Android Studio as instructed https://facebook.github.io/react-native/docs/getting-started.html#1-install-android-studio – Harry Moreno Jun 07 '18 at 02:32
  • 1
    Here update command line for brew install android platform tools above. Please try: brew cask install android-platform-tools – Nguyen Thuong Thong Apr 04 '20 at 14:56
  • 3
    ```android avd``` is deprecated. Use ```android list avd```. – cmcodes Jun 16 '20 at 18:24
4

It happened to me that I had an instance of the packager running with an old project (I ran react-native start as usual). I was using Ubuntu 14.04. So what I did was to stop that instance and go to my project folder and in two different console tabs I ran these two commands separately:

npm start #here I used to run react-native start
react-native run-android

npm start is defined in my package.json as:

"start": "node_modules/react-native/packager/packager.sh"

I don't know if there is a sort of confusing stuff for react-native but that did the trick.

Rowinson Gallego
  • 850
  • 1
  • 9
  • 14
4

On Windows 10 and Android Studio you can go in Android Studio to "File"->"Settings" in Settings then to "Appearance & Behavior" -> "System Settings" -> "Android SDK". In the Tab "SDK Tools" active:

  • "Android SDK Build-Tools .."
  • "Android Emulator"
  • "Android SDK Plattform-Tools"
  • "Android SDK Tools"

If all installed then you can start the Emulator in Android Studio with "Tools" -> "Android" -> "AVD Manager". If the Emulator run you can try "react-native run-android"

Beachhouse
  • 4,972
  • 3
  • 25
  • 39
Edelfix
  • 871
  • 1
  • 7
  • 8
4

If emulator not installed then try this command, (if homebrew installed)

brew install android-platform-tools

might be it will help.

Pankaj bhalala
  • 163
  • 1
  • 11
2

Had a similar problem. I updated my Genymotion and my android SDK's/libraries/dependencies and all seemed to work. To update my SDK's I used android sdk manager {ANDROID_SDK_FOLDER}/tools/android sdk

2

In my case, there was an issue with the android/gradlew file. I think this happens when we move the code from Windows to Mac OS.

Reference:- https://stackoverflow.com/a/62216646/4786087

I was able to clean the android/gradlew file by running the following commands -

Step 1. On android folder cmd run

chmod +x gradlew

Step 2. After that run

./gradlew clean

Step 3. Next in the root of the project, run

react-native run-android

This should start building the app and launch it in the simulator if everything else is fine.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-ask). – Community Sep 22 '21 at 09:39
1

Try

  • brew cask install android-platform-tools
  • adb reverse tcp:9090 tcp:9090
  • run the app
Anuj
  • 402
  • 8
  • 16
0

In my case, this was happening because the android/gradlew file did not have execute permission. Once granted, this worked fine

Allen Paul
  • 129
  • 1
  • 3
0

You probably haven't run the Android SDK in forever. So you probably just have to update it. If you open the Android Studio Software it'll probably let you know that and ask to update it for you. Otherwise refer to following link: Update Android SDK

Ahmedakhtar11
  • 1,076
  • 11
  • 7