Skip to content

Instantly share code, notes, and snippets.

@lostrouter
Created April 20, 2020 22:30
Show Gist options
  • Save lostrouter/5d2709d0959e0e5efe834f80b1f06283 to your computer and use it in GitHub Desktop.
Save lostrouter/5d2709d0959e0e5efe834f80b1f06283 to your computer and use it in GitHub Desktop.
How to create terminal shortcuts to launch android emulator without opening android studio

How to create terminal shortcuts to launch Android Emulator without opening android studio

Windows

In your bash terminal

code ~/.bashrc

Copy and paste the following code into the file. replace <userName> with the your windows user name.

export ANDROID_SDK=/c/Users/<userName>/AppData/Local/Android/sdk
alias android-emulator="$ANDROID_SDK/emulator/emulator -avd $@"
alias android-list="$ANDROID_SDK/emulator/emulator -list-avds"
alias pixel2="android-emulator Pixel_2_API_28 -no-snapshot"

This is creating a command shortcut to:

  1. list available virtual devices
  2. launch the emulator for any virtual device you might specify
  3. launch the Pixel 2 emulator we created when setting up the environment
  4. create an environment variable with the path to the location of the android sdk

If you are not sure what your user name is run the following commands.

cd ~
pwd

You should see an output like

/c/Users/<userName>/

Run this command to make the shortcuts available in the terminal

source ~/.bashrc

Run this command shortcut to list available virtual android devices.

android-list

If it does not, update this line in .bashrc, and replace Pixel_2_API_28 with the value returned from android-list

alias pixel2="android-emulator Pixel_2_API_28 -no-snapshot"

if you had to update the line, run this command again.

source ~/.bashrc

Make sure that your emulator is closed, and android studio is closed. then in the terminal you can run

pixel2

To make sure that the bash_profile file is being loaded with each new terminal: Close the emulator. Open a new terminal. Run pixel2

MacOS

bash

In your bash terminal

code ~/.bash_profile

Copy and paste the following lines of code to the end of the file that just opened, and save the file.

alias android-emulator="$ANDROID_SDK/emulator/emulator -avd $@"
alias android-list="$ANDROID_SDK/emulator/emulator -list-avds"
alias pixel2="android-emulator Pixel_2_API_28 -no-snapshot"

This is creating a command shortcut to:

  1. list available virtual devices
  2. launch the emulator for any virtual device you might specify
  3. launch the Pixel 2 emulator we created when setting up the environment

Run this command make the shortcuts available in the current terminal. If the it was successful, there won't be any output.

source ~/.bash_profile

Next run this command shortcut to list available virtual android devices.`

android-list

If it does not, update this line in .bash_profile, and replace Pixel_2_API_28 with the value returned from android-list

alias pixel2="android-emulator Pixel_2_API_28 -no-snapshot"

If you had to update the line, run this command again.

source ~/.bash_profile

Make sure that your emulator is closed, and android studio is closed. then in the terminal you can run

pixel2

To make sure that the bash_profile file is being loaded with each new terminal: Close the emulator. Open a new terminal. Run pixel2

zsh

In your zsh terminal

code ~/.zshrc

Copy and paste the following lines of code to the end of the file that just opened, and save the file.

alias android-emulator="$ANDROID_SDK/emulator/emulator -avd $@"
alias android-list="$ANDROID_SDK/emulator/emulator -list-avds"
alias pixel2="android-emulator Pixel_2_API_28 -no-snapshot"

This is creating a command shortcut to:

  1. list available virtual devices
  2. launch the emulator for any virtual device you might specify
  3. launch the Pixel 2 emulator we created when setting up the environment

Run this command make the shortcuts available in the current terminal. If the it was successful, there won't be any output.

source ~/.zshrc

Next run this command shortcut to list available virtual android devices.`

android-list

If it does not, update this line in .zshrc, and replace Pixel_2_API_28 with the value returned from android-list

alias pixel2="android-emulator Pixel_2_API_28 -no-snapshot"

If you had to update the line, run this command again.

source ~/.zshrc

Make sure that your emulator is closed, and android studio is closed. then in the terminal you can run

pixel2

To make sure that the .zshrc file is being loaded with each new terminal: Close the emulator. Open a new terminal. Run pixel2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment