How to connect Android Device in Appium

 

To connect an Android device in Appium, follow these steps. This setup will allow Appium to communicate with the device for automated testing.


Prerequisites

  • Install Java JDK
  • Install Android Studio or SDK Tools
  • Install Node.js
  • Install Appium Server
  • Install Appium Inspector (optional for inspecting elements)
  • Enable Developer Options and USB Debugging on your Android device
  • USB Cable or Wi-Fi ADB connection



Step-by-Step: Connect Android Device to Appium


Step 1: Enable Developer Mode on Android

  • Go to Settings > About Phone
  • Tap Build Number 7 times to enable Developer Options
  • Go to Settings > Developer Options
  • Enable USB Debugging


Step 2: Connect Device via USB

  • Use a USB cable to connect your phone to your PC.

  • Allow the USB debugging prompt on your device.



Step 3: Verify Device Connection with ADB

Open Command Prompt (Windows) or Terminal (Mac/Linux) and run:

adb devices



You should see your device listed:

List of devices attached
emulator-5554   device

If unauthorized, replug the device and allow debugging access.



Step 4: Start Appium Server

You can use either of the two:

  • Appium Desktop App → Click Start Server

  • Command Line:

appium


Ensure it’s running on:

http://127.0.0.1:4723/



Step 5: Desired Capabilities to Connect Device

Below is a sample configuration for your test script or Appium Inspector:

{
  "platformName": "Android",
  "deviceName": "Android Device",
  "automationName": "UiAutomator2",
  "udid": "your_device_udid",
  "appPackage": "com.example.app",
  "appActivity": "com.example.app.MainActivity"
}



Use adb devices to get udid
Use adb shell pm list packages to find appPackage
Use adb shell dumpsys window windows | grep -E 'mCurrentFocus' for appActivity




Step 6: Run Your Test

You can now run your Appium test using Java, Python, or any supported language binding. For example, in Java:



DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("platformName", "Android");
caps.setCapability("deviceName", "Android Device");
caps.setCapability("automationName", "UiAutomator2");
caps.setCapability("appPackage", "com.example.app");
caps.setCapability("appActivity", "com.example.app.MainActivity");

AndroidDriver driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), caps);





Check if something is not working:

Always check if your device is listed with adb devices
Ensure the Appium version supports your Android version
Restart adb server using:

adb kill-server
adb start-server