Mobile Development 6 min read

Building Uiautomator 1.0 Jar with Ant in Android Studio

This guide explains how to construct a Uiautomator 1.0 jar package using Ant within Android Studio, covering required SDK tools, project setup, build.xml generation, Gradle integration, jar composition, execution flow, and a sample custom test service implementation for Android testing.

360 Quality & Efficiency
360 Quality & Efficiency
360 Quality & Efficiency
Building Uiautomator 1.0 Jar with Ant in Android Studio

Uiautomator is an Android native testing framework; version 1.0 offers higher permissions and flexible execution, while version 2.0 provides tighter app‑level integration. Because the latest Android SDK no longer includes Ant support, building a Uiautomator 1.0 jar requires downloading the legacy sdk-tools (e.g., Linux , macOS ) and copying its tools/ directory into the local SDK.

In Android Studio, create a regular project, import the necessary Uiautomator dependencies, and add a test class. Open a console, navigate to the /sdk/tools/ directory, and run the Ant command to generate a build.xml file for the project.

Next, edit the generated build.xml to comment out incompatible sections, then add an Ant task definition to the module’s build.gradle . After syncing Gradle, the new task appears under Tasks → other → ant-build . Executing ant-build compiles the project and produces an APK in [module]/bin .

The resulting Uiautomator 1.0 jar consists mainly of .dex files and a META-INF directory, similar to a standard Android APK. By unpacking the jar, you can see its structure and even replace the jar with an APK to run tests.

Running a test involves invoking the Uiautomator command line, which launches the com.android.commands.uiautomator.Launcher class. The Launcher parses arguments and calls RunTestCommand.run() , which delegates to UiAutomatorTestRunner.run() . This method initializes UiAutomationShellWrapper , connects to the system test service, and obtains a UiAutomation object that provides APIs for UI interaction (e.g., querying elements, sending key events, swiping, clicking).

To simulate a custom test service, the guide outlines a lightweight implementation where multiple services can be registered or unregistered dynamically. It demonstrates creating a Java test class MyUiAutomation , building the corresponding APK, and executing the test script.

Mobile DevelopmentAndroidtestingUiAutomatorAnt
360 Quality & Efficiency
Written by

360 Quality & Efficiency

360 Quality & Efficiency focuses on seamlessly integrating quality and efficiency in R&D, sharing 360’s internal best practices with industry peers to foster collaboration among Chinese enterprises and drive greater efficiency value.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.