Android Setup — Android Studio, ADB, Emulators

9 min read

Android automation with Appium requires three things: a Java SDK, the Android SDK (which contains ADB and the emulator), and an AVD to target. Android Studio bundles most of this in one installer. This lesson walks through the setup end to end and covers the commands you will use every day.

Install Android Studio

Download Android Studio from developer.android.com/studio. Run the installer. During setup, accept the defaults — Android Studio installs the Android SDK, the emulator, and platform tools automatically.

After installation, note where the SDK lives:

  • macOS: ~/Library/Android/sdk
  • Windows: C:\Users\<user>\AppData\Local\Android\Sdk
  • Linux: ~/Android/Sdk

This path is your ANDROID_HOME. Set it and add the key directories to PATH:

export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$ANDROID_HOME/emulator:$ANDROID_HOME/platform-tools:$ANDROID_HOME/cmdline-tools/latest/bin:$PATH

Add these lines to ~/.zshrc and run source ~/.zshrc.

ADB — Android Debug Bridge

ADB is the primary command-line tool for communicating with Android devices and emulators. It runs a server daemon (adb server) that bridges your terminal to any connected Android device via USB or TCP.

Core commands you will use constantly:

# List connected devices and running emulators
adb devices
 
# Install an APK
adb install path/to/app.apk
adb install -r path/to/app.apk   # -r keeps data on reinstall
 
# Push a file to the device
adb push localfile.txt /sdcard/localfile.txt
 
# Open a shell on the device
adb shell
 
# Clear app data (useful for test cleanup)
adb shell pm clear com.example.myapp
 
# Grant a permission without the dialog
adb shell pm grant com.example.myapp android.permission.ACCESS_FINE_LOCATION
 
# Get a running device property
adb shell getprop ro.product.model
adb shell getprop sys.boot_completed   # returns 1 when fully booted
 
# Capture a screenshot
adb exec-out screencap -p > screen.png
 
# Record the screen
adb shell screenrecord /sdcard/test.mp4

If adb devices returns "unauthorized" for a device, unlock the device screen, look for the USB debugging prompt, and tap "Always allow from this computer."

Creating an Android Virtual Device (AVD)

Open Android Studio → More Actions → Virtual Device Manager → Create Device.

Choose a hardware profile (Pixel 6 is a safe default), select a system image (download the latest stable x86_64 image for speed), and create the AVD. Note the name you give it.

Alternatively, from the command line:

# List available system images
sdkmanager --list | grep "system-images"
 
# Download a system image (e.g., API 34, Google APIs, x86_64)
sdkmanager "system-images;android-34;google_apis;x86_64"
 
# Create an AVD
avdmanager create avd \
  --name "Pixel6_API34" \
  --package "system-images;android-34;google_apis;x86_64" \
  --device "pixel_6"

Starting the emulator

# List available AVDs
emulator -list-avds
 
# Start an emulator (with GUI)
emulator -avd Pixel6_API34
 
# Start headlessly (required for CI)
emulator -avd Pixel6_API34 -no-window -no-audio -no-snapshot-load

Wait for boot before running tests:

# Wait for ADB to see the device
adb wait-for-device
 
# Poll until sys.boot_completed = 1
until [ "$(adb shell getprop sys.boot_completed 2>/dev/null)" = "1" ]; do
  sleep 2
done
echo "Emulator is ready"

Connecting Appium to an emulator

Once the emulator is running and adb devices shows it, Appium can connect. The deviceName capability must match the string returned by adb devices:

$ adb devices
List of devices attached
emulator-5554   device

So deviceName would be "emulator-5554".

UiAutomator2Options options = new UiAutomator2Options();
options.setDeviceName("emulator-5554");
options.setPlatformVersion("14");
options.setApp("/absolute/path/to/app.apk");
AndroidDriver driver = new AndroidDriver(new URL("http://127.0.0.1:4723"), options);

Connecting to a real Android device

  1. Enable Developer Options on the device: go to Settings → About Phone → tap Build Number seven times
  2. In Developer Options, enable USB Debugging
  3. Connect via USB cable
  4. Run adb devices — the device should appear as "device" (not "offline" or "unauthorized")
  5. Accept the "Allow USB debugging" prompt on the device

For wireless ADB (Android 11+):

adb pair <ip>:<port>    # use the pairing code shown in Developer Options
adb connect <ip>:5555   # for regular ADB commands

Useful SDK tools

ToolPurpose
avdmanagerCreate, list, delete AVDs
sdkmanagerInstall/update SDK packages
emulatorStart AVDs
adbCommunicate with devices
apkanalyzerInspect APK contents, get package name

Get the package name from an APK you don't recognise:

apkanalyzer manifest print app.apk | grep package
# or
aapt dump badging app.apk | grep package

This is the value you use for appPackage in your Appium capabilities.

// tip to track lessons you complete and pick up where you left off across devices.