Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run react-native on android emulator

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?

like image 710
alborozd Avatar asked Jul 25 '16 21:07

alborozd


People also ask

Can React Native app run on Android device?

Plug in your device via USB​ Let's now set up an Android device to run our React Native projects. Go ahead and plug in your device via USB to your development machine. Now check that your device is properly connecting to ADB, the Android Debug Bridge, by running adb devices .

Which emulator is best for React Native?

React Native recommends the Genymotion emulator out of the box. For many developers (and corporations), the price tag on Genymotion is not worth the expense. We'll be using the free Android Studio emulator for this walkthrough.

What is emulator in React Native?

React Native is a mobile development framework for building cross-platform apps that run and feel truly native on both iOS and Android. With React Native, you can choose to test run your app either on an emulator or on a physical device.


3 Answers

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 .

like image 84
Rizwan Jamal Avatar answered Sep 28 '22 04:09

Rizwan Jamal


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

like image 25
Anatolii Olshevskyi Avatar answered Sep 28 '22 06:09

Anatolii Olshevskyi


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

like image 43
Aayush Bhattacharya Avatar answered Sep 28 '22 06:09

Aayush Bhattacharya