Setting up Android Emulator without Android Studio

Jai Kathuria
5 min readAug 20, 2022

--

This article will help you set up Android Virtual Studio (AVD) with command line tools only without installing the whole Android Studio.

Let’s start the process by setting up an Android SDK on our system.

1. Downloading Command Line tools

i. Download the latest “command line tools only” package from the Android Studio downloads page based on your platform
ii. Now extract this package into a new directory of your choice like android_sdk. This new directory is your Android SDK directory.

iii. In the unzipped cmdline-tools directory, create a sub-directory called latest.

iv. Move the original cmdline-tools directory contents, including the lib directory, bin directory, NOTICE.txt file, and source.properties file, into the newly created latest directory.

Once you are done with these steps, your android_sdk will look something like:

android_sdk directory with cmdline-tools

You can now use the command line tools from this location.

2. Setting up Command Line tools

The most critical piece of setting up command line tools is setting up the environment variables.
There are a few environment variables that we need to set up right now before we move ahead like ANDROID_HOME,ANDROID_SDK_ROOT and ANDROID_AVD_HOME.

i. ANDROID_HOME,ANDROID_SDK_ROOT should point to the android_sdk directory. Which in my case, would become $HOME/Documents/android_sdk.

ii. ANDROID_AVD_HOME Points to the directory that contains all AVD-specific files, which mostly consist of very large disk images. You might want to specify a location with sufficient disk space. I am sticking to the default location i.e. $HOME/.android/avd.
To make this work make sure .android does exist in your $HOME directory and it contains a directory called avd.

setting up environment variables

Once the environment variables are set we need to install a few packages like Emulator, Platform, Platform tools, and System Image which will be used to create and run AVD

To install these packages we will use sdkmanager that comes with command line tools. First, open a terminal in the android_sdk directory and run the following commands for each of the packages

  1. Emulator
    ./cmdline-tools/latest/bin/sdkmanager --install "emulator"
  2. Platform Tools
    It includes tools that interface with the Android platform, primarily adb and fastboot
    ./cmdline-tools/latest/bin/sdkmanager --install "platform-tools"
  3. SDK Platforms
    This includes Sources for Android which is required to compile the builds for that version and several System Images which are required to run that version of android in the emulator. Because of this, you need to download a specific version of the platform based on which version of Android you want to run in the emulator. You can select the version you want to install here.
    I want to run android 11 so I need to install version 30 of the platform
    ./cmdline-tools/latest/bin/sdkmanager --install "platforms;android-30"
  4. System Image
    This would be the image of android that will run in the emulator. Just like the SDK Platform, it would be based on which version of Android you want to run.
    To see which different images are available for the version that you want to run, try
    ./cmdline-tools/latest/bin/sdkmanager --list | grep "system-images;android-30"
    Among different images available for the version you want to run, you need to choose based on your system.
    Like if you have, 64-bit Intel System you should install x86_64 image
    Or if you have a 64-bit ARM-based system, you should install arm64-v8a
    Based on my system config, I am going ahead with google_apis;arm64-v8a
    ./cmdline-tools/latest/bin/sdkmanager --install "system-images;android-30;google_apis;arm64-v8a"
Installing packages emulator, platform-tools, platform, and system-image

3. Adding tools to environment path [Optional]

We have now set the critical environment variable and installed the required packages. To make life easier we can add these tools to our system environment path variable so that we can access these tools from any place.

You can add command line tools, platform tools, and the emulator in the path like:

adding emulator, command line tools, and platform tools in the system path

4. Creating AVD

Now that everything else is ready we can jump onto creating our virtual device. The command that we will use to create the virtual device is avdmanager create avd. This command accepts some additional parameters like:
i. --name: This would give an identifier to your virtual device
ii. --package: This is the system image that we have downloaded for our virtual device
iii. --device: This would be the device definition you want to give your virtual device. Example, you can give your virtual device definition of pixel 4
avdmanager create avd --name pixel-android-11 --package 'system-images;android-30;google_apis;arm64-v8a' --device 'pixel_4'

Creating AVDs with command line

5. Starting AVD

So far we have successfully created an android virtual device with devices definition of pixel 4 which would be running Android 11.
To start this virtual device we need to use the emulator command.
emulator @pixel-android-11 -netdelay none -netspeed full

You have followed me till this step then the outcome should be that you should see an AVD running successfully 🎉

AVD running successfully

But if you face any issue following the steps, do let me know in the comments, would love to help 🙌

You can also tweet to me @_jaikathuria

--

--