Skip to content

Install the UiAutomator2 Driver

You can't do much with Appium unless you have a driver, which is an interface that allows Appium to automate a particular platform.

Info

For this quickstart guide, we're going to be automating an app on the Android platform, because the system requirements for Android automation via Appium are the same as for Appium itself (whereas the iOS driver, for example, requires you to be using macOS).

The driver we're going to use is called the UiAutomator2 Driver. It's worth visiting that driver's documentation and bookmarking it, because it will be an invaluable reference down the line.

Set up Android automation requirements

According to the driver, in addition to a working Appium server, we also need to set up the following:

Android SDK

  • The easiest way to set up the Android SDK requirements is by downloading Android Studio. We need to use its SDK manager (Settings -> Appearance & Behavior -> System Settings -> Android SDK) to download the following items:
    • Android SDK Platform (select whichever Android platform we want to automate, for example, API level 30)
    • Android SDK Platform-Tools
  • If you wish, you can also download these items without Android Studio:
  • Set up the ANDROID_HOME environment variable to point to the directory where the Android SDK is installed. You can usually find the path to this directory in the Android Studio SDK manager. It will contain the platform-tools and other directories.

Java JDK

  • Install the Java JDK (for the most recent Android API levels, JDK 9 is required, otherwise JDK 8 is required). You can download this from Oracle or Adoptium. Make sure you get the JDK and not the JRE.
  • Set up the JAVA_HOME environment variable to point to the JDK home directory. It will contain the bin, include, and other directories.

Prepare the Device

  • If using an emulator, use Android Studio to create and launch an Android Virtual Device (AVD). You may need to download the system images for the API level of the emulator you want to create. Using the AVD creation wizard in Android Studio is generally the easiest way to do all of this.
  • If using a real device, you should set it up for development and enable USB Debugging.
  • With the emulator or device connected, you can run adb devices (via the binary located at $ANDROID_HOME/platform-tools/adb) to verify that your device shows up as connected.

Once your device shows up as connected in adb, and you've verified that the environment variables are set up correctly, you should be good to go! If you ran into problems with any of these steps, refer to the driver documentation, or the various Android or Java documentation sites as necessary.

Also, congratulations: whether or not you intended to, you now have the Android developer toolchain set up on your system, so you can get busy making Android apps if you want!

Install the driver itself

Since the UiAutomator2 driver is maintained by the core Appium team, it has an 'official' driver name that you can use to install it easily via the Appium Extension CLI:

appium driver install uiautomator2

It should produce output that looks something like:

Attempting to find and install driver 'uiautomator2'
✔ Installing 'uiautomator2' using NPM install spec 'appium-uiautomator2-driver'
Driver [email protected] successfully installed
- automationName: UiAutomator2
- platformNames: ["Android"]

Running this command will locate and install the latest version of the UiAutomator2 driver, making it available for automation. Note that when it is installed it tells you what platforms it is valid for (in this case, Android), and what automation name (the appium:automationName capability) must be used to select this driver for use during an Appium session (in this case, UiAutomator2).

Note

In this quickstart we have used the Extension CLI to install the UiAutomator2 driver, but if you are incorporating Appium into a Node.js project, you might prefer to use npm to manage Appium and its connected drivers. To learn more about this technique, visit the guide on managing Appium extensions.

Now, start the Appium server again (run appium), and you should see that the newly-installed driver is listed as available:

[Appium] Available drivers:
[Appium]   - [email protected] (automationName 'UiAutomator2')

With the Android setup complete and the UiAutomator2 driver installed, you're ready to write your first test! Now select your preferred language and give it a shot: