Please post your Web Driver questions in official Web Driver forum

Thursday, May 28, 2015

Appium and Android setup

Back to Appium Tutorial Index

Android Requirements
  • Android SDK API >= 17 (Additional features require 18/19)
  • Appium supports Android on OS X, Linux and Windows. Follow these directions for setting up your environment properly for testing on different OSes:
Android setup does not differ greatly on different operating system. Let’s look at detailed setup instructions for Ubuntu  -

Installing Appium on MAC or Windows 

Use following download links to for OSX and Appium.exe for Windows
The project is available on GitHub

Installing Appium on Ubuntu  -

Install node.js (v0.10 or greater) -

Since appium server is written in node.js, first node.js needs to be installed. Following this appium can be installed from npm -

Setup with Ubuntu: curl -sL | sudo bash -
Then install with Ubuntu: sudo apt-get install -y nodejs

DON’T install node js using above method, it would result in following error when starting appium -
error: Appium will not work if used or installed with sudo. Please rerun/install as a non-root user. If you had to install Appium using `sudo npm install -g appium`, the solution is to reinstall Node using a method (Homebrew, for example) that doesn't require sudo to install global npm packages.

To fix it -

  • Download latest nodejs linux binaries (or windows, mac if you are not on linux) form
  • Extract into a folder that doesn't need sudo rights to access, for example your home folder.
tar -xvf <downloaded_binary_tar.gz>
{extracted file looks as following in my home directory -
  • Add the following line to your ~/.bashrc file.
export PATH=$PATH:<full_path_of_the_extracted_node_folder>/bin

appium is installed in bin folder and updating path would let you execute appium from command line as described later -
refresh bashrc so you don’t have to logout and login -
source ~/.bashrc
  • Open a new terminal and execute
npm install -g appium
    {appium installation looks as following on my ubuntu -
  • Now start appium as -
cd /home/tarun/node-v0.12.2-linux-x64/bin
If everything goes right then you would have appium server up and running as following  
info: Welcome to Appium v1.3.7 (REV 72fbfaa116d3d9f6a862600ee99cf02f6d0e2182)
info: Appium REST http interface listener started on
info: Console LogLevel: debug

Install Android SDK

  • Install android sdk from -

Unpack the .zip file you've downloaded. The SDK files are downloaded separately to a user-specified directory

By default, Android SDK does not include everything required to start development. The SDK separates tools, platforms, and other components into packages that can be downloaded as needed using the Android SDK Manager. Hence we must first download a few packages and add to Android SDK.
  • Downloading additional packages and latest SDK tools. launch the Android SDK Manager.
Open a terminal and navigate to the tools/ directory in the location where the Android SDK was installed, then execute android sdk.
For ex it looks as following on my ubuntu -
cd /Documents/mine/lib/android-sdk-linux/tools$
./android &

  • As a minimum when setting up the Android SDK, you should download the latest tools and Android platform:
    1. Open the Tools directory and select:
      • Android SDK Tools
      • Android SDK Platform-tools
      • Android SDK Build-tools (highest version)
    1. Open the first Android X.X folder (the latest version) and select:
      • SDK Platform
      • A system image for the emulator, such as ARM EABI v7a System Image
  1. AndroidTools.png
3. Get the support library for additional APIs
The Android Support Library provides an extended set of APIs that are compatible with most versions of Android.
Open the Extras directory and select:
    • Android Support Repository
    • Android Support Library
  • AndroidTools.png
  • Once you've selected all the desired packages, continue to install:

  1. Click Install X packages.
  2. In the next window, double-click each package name on the left to accept the license agreement for each.
  3. Click Install.

The download progress is shown at the bottom of the SDK Manager window. Do not exit the SDK Manager or it will cancel the download.

Creating new emulator
Android emulator can be created from command line or using AVD (Android Virtual Device manager). AVD can be launched from Android SDK Manager as following -
Android SDK Manager > Tools > Manage AVDs  - launches Android Virtual Device (AVD) manager
You can create a new device or select any of the existing Device Definitions, for example select Nexus 5 by Google and click Create AVD button

Select Target, CPU/ABI, Skin and click ok to set up new virtual device. When you click Ok then device would be listed under “Android Virtual Devices” tab -

Select device > click Start button and Launch the device. This would launch Android emulator -

NOTE: if Android emulator opens a blank screen then select Emulation Options > Use Host GPU and start emulator again. This would also increase the emulator performance drastically.

Setup ANDROID_HOME variable

Finally, set $ANDROID_HOME to be your Android SDK path. This looks as following on my ubuntu -
  • export ANDROID_HOME=/home/tarun/Documents/mine/lib/android-sdk-linux
  • export PATH=$PATH:/home/tarun/Documents/mine/lib/android-sdk-linux/tools
  • and then execute source ~/.bashrc
Install Android Debug Bridge (adb) -
Execute following command to install adb -
sudo apt-get install android-tools-adb
Android Debug Bridge (adb) is a command line tool that lets you communicate with an emulator or android device. It is a client-server program and includes three components:
  • A client, which runs on development machine. You can invoke a client from a shell by issuing an adb command. Other Android tools such as the ADT plugin and DDMS also create adb clients. For example if you want to see list of emulator/devices running then execute following command -
adb devices
  • A server, which runs as a background process on development machine. The server manages communication between the client and the adb daemon running on an emulator or device.
  • A daemon, which runs as a background process on each emulator or device instance.
Refer ADB for more on this topic.

You can find the adb tool in <sdk>/platform-tools/ directory. It is available on following directory on my linux - /home/tarun/Documents/mine/lib/android-sdk-linux/platform-tools

Appium Inspector

If you installed appium on OSX or Windows using appium binary then you can use appium inspector to inspect to inspect app. Appium inspector has two functions - 
  • Inspect elements in app
  • Enable record and playback

Appium inspector does not work very well with android. Appium encourages to use uiautomatorviewer. An inspector tool from Google which is same as Appium inspector. You can find information on this here

Before using UIAutomatorViewer you should shut down appium as appium uses UIAutomatorViewer internally and this will prevent UIAutomatorViewer from working.
Once you have android SDK installed then you can start UIAutomatorViewer from command line - 


This would start UiAutomatorViewer as - 

Now open the app (for example calculator) in emulator or device and click on Device Screenshot (uiautomator dump) in the UIAutomatorViewer menu.
Following this you would see the snapshot of application in UIAutomatorViewer as - 

Now you can analyze the app element by hovering mouse on them. Mousehover would highlight the element in red circle in UIAutomatorViewer and would detail down the hierarchy in RHS. 
Fork me on GitHub