Resolving UIAutomator 1.0 NoClassDefFoundError on Android R Emulator

The article explains why UIAutomator 1.0 scripts fail on the Android R emulator due to a missing android.test.RepetitiveTest class, analyzes the stack trace to locate the error in UiAutomatorTestRunner, and provides a workaround by manually initializing the test framework via app_process.

360 Quality & Efficiency
360 Quality & Efficiency
360 Quality & Efficiency
Resolving UIAutomator 1.0 NoClassDefFoundError on Android R Emulator

Background : Android Studio 3.6 introduces an Android R preview emulator with ARM support, but executing UIAutomator 1.0 scripts on this emulator triggers incompatibility errors.

Exception details : The test runner prints a deprecation warning and then throws a java.lang.NoClassDefFoundError: Landroid/test/RepetitiveTest with a full stack trace, as shown below.

Warning: This version of UI Automator is deprecated. New tests should be written using UI Automator 2.0 which is available as part of the Android Testing Support Library.
See https://developer.android.com/training/testing/ui-testing/uiautomator-testing.html for more details.
INSTRUMENTATION_STATUS: stream=
Test results for WatcherResultPrinter=Test run aborted due to unexpected exception: Failed resolution of: Landroid/test/RepetitiveTest;
java.lang.NoClassDefFoundError: Failed resolution of: Landroid/test/RepetitiveTest;
    at com.android.uiautomator.testrunner.UiAutomatorTestRunner$WatcherResultPrinter.startTest(UiAutomatorTestRunner.java:297)
    at junit.framework.TestResult.startTest(TestResult.java:168)
    ... (additional stack frames) ...
Caused by: java.lang.ClassNotFoundException: android.test.RepetitiveTest
    ... 10 more
Time: 0.039
OK (1 test)
INSTRUMENTATION_STATUS: shortMsg=Failed resolution of: Landroid/test/RepetitiveTest;
INSTRUMENTATION_STATUS_CODE: -1

Analysis of the stack trace : The error originates in

com.android.uiautomator.testrunner.UiAutomatorTestRunner$WatcherResultPrinter.startTest

, where the missing android.test.RepetitiveTest class is first referenced, causing the NoClassDefFoundError.

Root cause : Android R removed the android.test.base library, which UIAutomator 1.0 relies on. Consequently, the framework cannot locate the RepetitiveTest interface, leading to failure before any test case is executed.

Workaround / Solution : For projects that must continue using UIAutomator 1.0, start a Java process with app_process, manually initialize the UIAutomator test service, and then run UIAutomator 1.0 APIs. This approach requires manually managing test execution order because JUnit3 features are unavailable.

Further reading : Detailed implementation and principles of UIAutomator can be found in the article "Uiautomator 项目搭建与实现原理" (https://testerhome.com/articles/20078).

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Mobile DevelopmentAndroidtestingUIAutomatorAndroid RNoClassDefFoundError
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

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.