DEV Community

loading...

Start emulator and simulator from macOS terminal

Vanessa Soares
Software Engineer in Test β€’ open source πŸ’š β€’ she/her ela/dela β€’ proudly πŸ³οΈβ€πŸŒˆ
・2 min read

Simulators

If you like use the terminal and knows how slow it is for macOS to open Xcode and Android Studio in an attempt to get the emulators/simulators started, this article is for you.

Before going to the tutorial, make sure you have Xcode and Android Studio properly installed with their command line tools on your macOS.

With these two NPM packages that can help you, it's start-ios-simulator & start-android-emulator. Run the following commands to install:

For android emulator:

npm install -g start-android-emulator
Enter fullscreen mode Exit fullscreen mode

For iOS simulator:

npm install -g start-ios-simulator
Enter fullscreen mode Exit fullscreen mode

For android just run the command below and it will not only list the emulators available to start, it will also ask you if you intend to clean the device's data to start it.

Terminal

In the iOS simulator you will have all the options available to start.

Terminal

Starting Android Emulator

You can also run the default emulator command that's in that developer.android.com doc.

To list emulators:

emulator -list-avds
Enter fullscreen mode Exit fullscreen mode

Just reference the device's compiler path, start the emulator and specify the device name.

/Users/seu.user/Library/Android/sdk/emulator/emulator -avd Pixel_2_API_29 -netdelay none -netspeed full
Enter fullscreen mode Exit fullscreen mode

In your .bash_profile file you can even create an alias to run just a short command in the terminal.

export ANDROID_HOME=/Users/{YourUsername}/Library/Android/sdk/
alias run-emulator=”$ANDROID_HOME/emulator/emulator @Pixel_XL_API_27"
Enter fullscreen mode Exit fullscreen mode

Start iOS Simulator

Apple has simctl binary for interacting with iOS simulators from the command line. It's very similar to adb for Android. We can access all available options using the help command.

$ xcrun simctl help
Enter fullscreen mode Exit fullscreen mode

List all simulators:

xcrun simctl list --json
Enter fullscreen mode Exit fullscreen mode

To launch the simulator app:

open /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/
Enter fullscreen mode Exit fullscreen mode

If you want to start a specific simulator, just find the id listed in the xcrun sumctl list β€” json command and run the command:

xcrun simctl boot BE53CBFF-4900–4F10-A1D4-B451AB4C9E7E
open /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/
Enter fullscreen mode Exit fullscreen mode

Discussion (0)