6

Is there any way to open react native app and simulator using one command..

i mean some thing like : react-native run-android --emulator 'PIXEL_API_27'

i also try :

"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"android": "react-native run-android --emulator 'PIXEL_API_27'",
"test": "jest"

},

and run command npm run android but its complaining that error: unknown option--simulator'`

i am very new with react native. pls help me ....

Amjad
  • 330
  • 7
  • 22
  • There is no such option in react-native cli. I would suggest you reading the following which will explain you how to launch the emulator in command line : https://developer.android.com/studio/run/emulator-commandline . Then, you execute that command before the `run-android` one. – Fidan Hakaj Dec 05 '18 at 21:18

1 Answers1

10

There is currently no way to open a terminal by passing additional flags to react-native run-android.

So your problem is two fold. First how to run the emulator from the command line, and second how to chain that command with running your react-native project. Let's deal with them in that order.

Opening the emulator from the command line

It is possible to open an emulator via the command line. that is done with the emulator @avd command, replacing @avd with the name of your android virtual device. For example:

emulator @Nexus_5X_API_27_x86

To get the names of the installed android virtual devices on your machine run emulator -list-avds.

Now that your emulator is running let's get react-native running too.

Running the emulator and then running react-native run-android

I have found one issue with running the emulator from the command line, the emulator command keeps executing meaning that you cannot chain commands using &&. However you can run the emulator terminal in the background, by using & so we can chain the commands in the following way:

emulator @Nexus_5X_API_27_x86 & react-native run-android

If you are happy running the terminal in the background, this could be the solution for you.

For more settings for running the emulator from the command line see the docs


Be warned you may get errors when you try to run the emulator command. The most common that I have come across is the PANIC: Missing emulator engine program for 'x86' CPUS. This may require you to dive into your .bashrc or your .bash_profile to get the emulator command to behave. You can see more here

Andrew
  • 26,706
  • 9
  • 85
  • 101
  • 1
    But its saying `'emulator' is not recognized as an internal or external command,` – Amjad Dec 06 '18 at 17:39
  • As I said you may have to play around with you `.bashrc` Or `.bash_profile`. You probably have commands missing from it. The following is for setting up adb on a Mac https://stackoverflow.com/questions/17901692/set-up-adb-on-mac-os-x for windows this article has some suggestions https://www.androidcentral.com/installing-android-sdk-windows-mac-and-linux-tutorial – Andrew Dec 06 '18 at 17:52
  • @Amjad , For windows, make sure that `%LOCALAPPDATA%\Android\Sdk\emulator` is in your `PATH` User variable. Restart `command prompt` or `powershell`, then run `emulator '@Nexus_5X_API_27_Android_8.1'` Where by `Nexus_5X_API_27_Android_8.1` is your _Android Virtual Device (AVD)_ name. – steven7mwesigwa Dec 15 '20 at 20:03