DEV Community

Shivam Sharma
Shivam Sharma

Posted on

Run Android Emulator without installing Android Studio

Usually, we install Android Studio to run our code in its Android Emulator. This emulator is usually called AVD (Android Virtual Device) Emulator, which is a very handy tool especially if you don't want to setup your personal device for the testing usecase. But, sometimes you don’t need Android Studio but still need the AVD Emulator, so it's just overkill to install heavy Android Studio to just run Android Emulator.

So we'll see how we can install and run AVD Emulator without installing Android Studio. Here’s the step to step guide to install AVD Emulator to your Mac without installing Android Studio. Same can be followed for linux based devices.

Install Java (If already not)

Java is used to build and run the emulator and related tools. Java must be installed in your system. You can download Java by following below steps:

  1. Download appropriate Java package or installer from Official Oracle website

Java download

  1. If you use the installer(recommended), that will set appropriate paths as well.

Get Tools package

tools package is part of Android SDK, a group of packages that are needed for Android development. tools package is used for managing other packages to create AVD's. Here's the step for getting the tools package:

  1. Go to Official Android Studio download page.
  2. Scroll down to "Command line tools only" section.

Android SDK download

  1. Download the package according to your OS by clicking on it.
  2. Extract the package to the folder you want. I use below for my Macbook:
    1. Single User: /Users/shivamsharma/Library/Android/sdk
    2. Globally: /Library/Android/sdk
  3. Move content of cmdline-tools to a folder named latest inside cmdline-tools . e.g. Final path for bin becomes: /Users/shivamsharma/Library/Android/sdk/cmdline-tools/latest/bin

Add Environment variables

We need to add environment variable to our bash/zsh profile for Android and Java Executables. By doing this we'll be able to run the command line tools or binary files from evrywhere in the machine.

To do the same

  1. Add below content in your bash file e.g. ~/.zshrc:
######## Android #########
export ANDROID_SDK_ROOT="/Users/shivamsharma/Library/Android/sdk"
export ANDROID_HOME="/Users/shivamsharma/Library/Android/sdk" #(Deprecated, but some programs still using it to locate SDK)
export PATH="$ANDROID_HOME/cmdline-tools/latest/bin/:$PATH"
export PATH="$ANDROID_HOME/emulator/:$PATH"
export PATH="$ANDROID_HOME/platform-tools/:$PATH"
Enter fullscreen mode Exit fullscreen mode
  1. Source the bash file by running source ~/.zshrc. As we have added path of cmdline-tools/latest/bin/ in PATH so we can call CLI commands available in that folder from anywhere.

Download essential packages

Now, we will download platform-tools and emulator packages. 
platform-tools has some tools to communicate with Android devices when you plug them into your computer. emulator is the Android emulator.
We will use sdkmanager or sdkmanager.bat which are placed at cmdline-tools/bin to install them.

You can check if sdkmanager is working by running sdkmanager --list. This will give the list of packages available to install with sdkmanager.

sdkmanager --list output

  1. Run sdkmanager platform-tools emulator to install platform-tools and emulator. Read and accept licences.
  2. Install android image you are interested e.g. I am using android-34 here which is SDK for Android 14 by running sdkmanager "system-images;android-34;google_apis_playstore;arm64-v8a" "platforms;android-34". Read and accept licences by typing y.

Create AVD device

We will use the avdmanager command to create an AVD device. This command is usually placed in cmdline-tools/latest/bin directory, so if you've already config the environment variable correctly, you can just call the command from everywhere.

Here’s an example of a command about how to create an AVD device:

avdmanager create avd --name '${DeviceName}' --package "system-images;android-34;google_apis_playstore;arm64-v8a" -d pixel
Enter fullscreen mode Exit fullscreen mode

Replace ${DeviceName} with the device name you want.

You will be asked if you want to change some default configurations. You can change it later in config.ini the file that is located in the AVD directory, so for now we will just continue the installation.

You can create  any number of emulator by changing the device name in the above command

To create emulator with different Android version you can download the respective System image using command mentioned in previous step and use the system image name downloaded to create new emulator with with that android version

Run the emulator

Run the emulator using below command:

emulator -avd ${DeviceName} -no-snapshot-load
Enter fullscreen mode Exit fullscreen mode

Emulator Screenshot

Use control + c in the terminal to close the emulator. Or switch off the device emulator using android controls.

Steps Summary

  1. Install Java: https://www.oracle.com/java/technologies/downloads/#jdk23-mac
  2. Download and Unzip Android Cmd tools to a new folder https://developer.android.com/studio#command-line-tools-only
    • e.g. /Users/shivamsharma/Library/Android/sdk for single user, for global user at /Library/Android/sdk
  3. Move content of cmdline-tools to a folder named latest inside cmdline-tools . e.g. Final path becomes: /Users/shivamsharma/Library/Android/sdk/cmdline-tools/latest/bin
  4. Add below content in ~/.zshrc
######## Android #########
export ANDROID_SDK_ROOT="/Users/shivamsharma/Library/Android/sdk"
export ANDROID_HOME="/Users/shivamsharma/Library/Android/sdk"
export PATH="$ANDROID_HOME/cmdline-tools/latest/bin/:$PATH"
export PATH="$ANDROID_HOME/emulator/:$PATH"
export PATH="$ANDROID_HOME/platform-tools/:$PATH"
Enter fullscreen mode Exit fullscreen mode
  1. Reload source file: source ~/.zshrc. As we have added path of cmdline-tools/latest/bin/ in PATH so we can call CLI commands available in that folder from anywhere.
  2. Check if you can run sdkmanager --list
  3. Run sdkmanager platform-tools emulator to install platform-tools and emulator. Read and accept licences.
  4. Run sdkmanager "system-images;android-34;google_apis_playstore;arm64-v8a" "platforms;android-34" to install android image you are interested in e.g. using android-34 here which is SDK for Android 14. Read and accept licences.
  5. Create device with command avdmanager create avd --name '${DeviceName}' --package "system-images;android-34;google_apis_playstore;arm64-v8a" -d pixel
  6. Run emulator by emulator -avd ${DeviceName} -no-snapshot-load. -no-snapshot-load is there to load the device from fresh instead of from a snapshot.

Top comments (1)

Collapse
 
aylarose profile image
Ayla Rose

The guide on running the Android Emulator without installing Android Studio provides a streamlined approach for developers looking to test applications without the overhead of a full IDE. This method is particularly useful for those who want to focus on app development efficiently. For users interested in enhancing their music experience, exploring options like Deezer Premium APK can offer additional features and benefits. For more details, check out deezer premium apk.