Setup Android Emulator with Terminal
This guide provides instructions for setting up Android Emulator.
Pre Requisite
Install Emulator
First thing that we need to check if we have emulator. You can check by running:
jjdechavez@192 ~ % sdkmanager --list [=======================================] 100% Computing updates... Installed packages: Path | Version | Description | Location ------- | ------- | ------- | ------- build-tools;35.0.0 | 35.0.0 | Android SDK Build-Tools 35 | build-tools/35.0.0 build-tools;36.0.0 | 36.0.0 | Android SDK Build-Tools 36 | build-tools/36.0.0 cmake;3.22.1 | 3.22.1 | CMake 3.22.1 | cmake/3.22.1 emulator | 36.1.9 | Android Emulator | emulator ndk;27.1.12297006 | 27.1.12297006 | NDK (Side by side) 27.1.12297006 | ndk/27.1.12297006 platform-tools | 36.0.0 | Android SDK Platform-Tools | platform-tools platforms;android-35 | 2 | Android SDK Platform 35 | platforms/android-35
If you dont have the emulator just run sdkmanager "emulator" to install the package.
After installing emulator, we need to update our .zshrc to add our emulator $PATH.
# android export ANDROID_HOME="$HOME/Library/Android/sdk" # platform-tools has been moved into sdk export PATH="$ANDROID_HOME/platform-tools:$PATH" export PATH="$ANDROID_HOME/cmdline-tools/latest/bin:$PATH" export PATH="$ANDROID_HOME/emulator:$PATH" # added PATH
Download System Images and Platform Tools
We have options depending on your machine:
- Windows: sdkmanager --install "system-images;android-33;google_apis;x86_64"
- Mac/Linux: sdkmanager --install "system-images;android-33;google_apis;arm64-v8"
Create an Android Virtual Device (AVD)
We're going to use avdmanager to create a new AVD:
avdmanager create avd -n MyEmulator -k "system-images;android-33;google_apis;x86_64" -d pixel_3a
Note:
- -n MyEmulator Name of your AVD
- -k "system-images;android-33;google_apis;x86_64": System image to use
- -k pixel_3a: Device definition (e.g., pixel_3a, nexus_5x). You can list available device definitions using avdmanager list device.
Launch the Emulator
Launched the created AVD using the emulator command
emulator -avd MyEmulator
This process enables you to manage and run Android emulators directly from your terminal, providing a command-line-centric workflow for Android development and testing.