Skip to content
Tutorials Center
My learning

Topics

Lesson 7 of 37 ยท Architecture and Setup

Android SDK, adb and Emulators for Appium

Install the Android SDK, set ANDROID_HOME, create an emulator with avdmanager, connect a real phone with adb and verify everything before running Appium.

For Android automation, the Appium server needs the Android SDK on the machine where it runs. The SDK provides adb (Android Debug Bridge), the emulator, and platform tools the UiAutomator2 driver uses to install apps and talk to the device. Most "Appium cannot start my session" problems on Android turn out to be SDK or device problems, so it pays to set this up carefully and to verify it without Appium first.

All commands in this lesson are for your own terminal and are shown read-only.

What you need

  • JDK. A recent Java Development Kit (17 or newer is a safe choice); the SDK command line tools use it, and JAVA_HOME should point to it.
  • Android SDK. Easiest to get by installing Android Studio, which downloads it to a default folder. You can also use only the "command line tools" package.
  • Environment variables. ANDROID_HOME (or the older ANDROID_SDK_ROOT) pointing to the SDK folder, and its platform-tools and emulator folders on your PATH.

Typical values:

Terminal
# macOS / Linux (shell profile)
export JAVA_HOME=/path/to/jdk-17
export ANDROID_HOME=$HOME/Library/Android/sdk      # Linux often $HOME/Android/Sdk
export PATH=$PATH:$ANDROID_HOME/platform-tools:$ANDROID_HOME/emulator:$ANDROID_HOME/cmdline-tools/latest/bin

On Windows, set the same variables in System Properties, Environment Variables (for example ANDROID_HOME = C:\Users\you\AppData\Local\Android\Sdk), then open a new terminal.

Verify:

Terminal
adb --version
echo $ANDROID_HOME

Installing SDK packages

With the command-line tools you manage packages using sdkmanager:

Terminal
sdkmanager --list
sdkmanager "platform-tools" "emulator" "platforms;android-35" "system-images;android-35;google_apis;x86_64"

(On an Apple Silicon Mac use an arm64-v8a system image instead of x86_64.) Choose a google_apis image if your app needs Google services such as Maps or sign-in. Choose plain default for the smallest, fastest image.

Creating an emulator

An emulator instance is an AVD (Android Virtual Device).

Terminal
avdmanager create avd -n Pixel_8_API_35 -k "system-images;android-35;google_apis;x86_64" -d pixel_8
emulator -list-avds
emulator -avd Pixel_8_API_35

Hardware acceleration makes a huge difference: use Intel HAXM/Hypervisor on Windows and Intel Macs, or the built-in Hypervisor.Framework on Apple Silicon, and KVM on Linux. Without acceleration emulators are very slow, and tests time out.

For CI machines you usually start the emulator headless:

Terminal
emulator -avd Pixel_8_API_35 -no-window -no-audio -no-snapshot

Using a real device

  1. On the phone, enable Developer options (tap Build number seven times in About phone).
  2. Turn on USB debugging.
  3. Connect by USB and accept the "Allow USB debugging?" prompt.
  4. Run adb devices.

Real devices are slower to manage but reveal problems emulators hide: vendor skins, real sensors, performance and network behavior.

Verifying with adb

adb devices lists connected devices and emulators. The output has a header followed by one line per device with a serial and a state:

  • device: ready to use.
  • unauthorized: the phone has not accepted this computer's key yet.
  • offline: the connection is stale; try adb kill-server then adb start-server, or re-plug the cable.

Other commands you will use daily:

Terminal
adb -s emulator-5554 install shop-debug.apk
adb shell pm list packages | grep shop
adb shell dumpsys window | grep mCurrentFocus
adb logcat -d

The dumpsys window command is the classic way to discover the current appPackage and appActivity of an app that is on screen; you will use both in the UiAutomator2 capabilities lesson.

Parsing device lists in a stand-in

Scripts often parse adb devices to pick a device. The stand-in below parses a sample text shaped like that output (we cannot run adb here) and chooses the first ready device, which is the sort of helper you would add to a test runner.

JS Stand-in: parse an adb devices listing

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Naming an emulator consistently

Teams often generate AVD names from a pattern so CI and laptops agree. The stand-in builds the name and the matching system image string, and shows why arm and x86 images are separate.

JS Stand-in: build avdmanager arguments

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Troubleshooting checklist

  1. adb devices shows the device as device.
  2. ANDROID_HOME is set in the same environment that starts the Appium server (IDE-launched servers sometimes miss shell variables).
  3. The emulator has finished booting (adb shell getprop sys.boot_completed returns 1).
  4. Enough disk space and RAM; emulators need several gigabytes.
  5. Only one adb server is running; stray older adb binaries cause "daemon version mismatch" messages.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which tool lists connected Android devices and emulators?

    adb devices prints each connected serial and its state.
  2. 2. A device shows as unauthorized in adb devices. What should you do?

    The phone has not trusted this computer's key; the debugging prompt must be accepted.
  3. 3. Which environment variable should point at the Android SDK folder?

    ANDROID_HOME (or the older ANDROID_SDK_ROOT) is how Appium finds adb and the SDK tools.
  4. 4. Why do emulators need hardware acceleration?

    Acceleration (KVM, Hypervisor, HAXM) makes the virtual CPU fast enough for reliable tests.

Summary

  • Appium's Android support needs a JDK, the Android SDK, ANDROID_HOME and adb on the path.
  • Create emulators with avdmanager, choose images that match your CPU, and enable acceleration.
  • Real devices need Developer options and USB debugging accepted.
  • Verify with adb devices and boot-completed before blaming Appium.
  • Make sure the server process sees the same environment variables as your shell.

Next: Xcode and iOS Simulators