testing-samples: UiAutomator findObject is throwing IllegalStateException: UiAutomation not connected!

Getting below Exception for every consecutive execution

java.lang.IllegalStateException: UiAutomation not connected!
at android.app.UiAutomation.throwIfNotConnectedLocked(UiAutomation.java:971)
at android.app.UiAutomation.waitForIdle(UiAutomation.java:577)
at android.support.test.uiautomator.UiAutomatorBridge.waitForIdle(UiAutomatorBridge.java:112)
at android.support.test.uiautomator.UiDevice.waitForIdle(UiDevice.java:639)
at android.support.test.uiautomator.UiDevice.waitForIdle(UiDevice.java:629)
at android.support.test.uiautomator.UiDevice.getWindowRoots(UiDevice.java:1074)
at android.support.test.uiautomator.UiDevice.findObject(UiDevice.java:164)

observed throwing above exception immediately after executing below statement in logcat

W WindowManager: Attempted to remove non-existing token: android.os.Binder@2728fc2

Tested on API Level: 19, 21, 23 emulators, issue also replicating in real device Uiautomator Version: com.android.support.test.uiautomator:uiautomator-v18:2.1.2

Please let me know if you need any other information.

About this issue

  • Original URL
  • State: open
  • Created 8 years ago
  • Reactions: 8
  • Comments: 26 (1 by maintainers)

Commits related to this issue

Most upvoted comments

Why is there no way for UiAutomation to automatically reconnect on disconnect?

Also getting the exact same report, when submitting an app for Alpha Testing on the Play Store

I am also getting same issue, when running robo tests on Firebase Cloud test infrastructure.

Fatal Exception: java.lang.IllegalStateException: UiAutomation not connected!
       at android.app.UiAutomation.throwIfNotConnectedLocked(UiAutomation.java:1034)
       at android.app.UiAutomation.disconnect(UiAutomation.java:275)
       at android.app.Instrumentation.finish(Instrumentation.java:210)
       at android.support.test.runner.MonitoringInstrumentation.finish(MonitoringInstrumentation.java:351)
       at android.support.test.runner.AndroidJUnitRunner.finish(AndroidJUnitRunner.java:405)
       at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:394)
       at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1932)

I solved this problem by putting my program in the background process and increasing the priority of the program.

Can you let us know the steps you followed to resolve the issue? “I solved this problem by putting my program in the background process and increasing the priority of the program.”

Same problem on my test project while I ran my UItest without connect my computer. It happend when I let my test sleep for a while and it cannot be restart . At the end it reported java.lang.IllegalStateException: UiAutomation not connected! It there any ideas for this problem? Thanks.

I am also getting same issue, When I test the android UI interface for a long time and need to sleep for a long time

When I test the android Q UI interface for a long time and need to sleep for a long time, I found that after a long sleep, my test program was killed by the android system, causing Uiautomator to not run normally.

I solved this problem by putting my program in the background process and increasing the priority of the program.

AndroidRuntime: Process: com.example.android.testing.uiautomator.BasicSample, PID: 4216
AndroidRuntime: java.lang.IllegalStateException: UiAutomation not connected!
AndroidRuntime: 	at android.app.UiAutomation.throwIfNotConnectedLocked(UiAutomation.java:1198)
AndroidRuntime: 	at android.app.UiAutomation.disconnect(UiAutomation.java:294)
AndroidRuntime: 	at android.app.Instrumentation.finish(Instrumentation.java:249)
AndroidRuntime: 	at android.support.test.runner.MonitoringInstrumentation.finish(MonitoringInstrumentation.java:318)
AndroidRuntime: 	at android.support.test.runner.AndroidJUnitRunner.finish(AndroidJUnitRunner.java:389)
AndroidRuntime: 	at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:378)
AndroidRuntime: 	at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2196)

Same issue when submitting for Open Beta on the Play Store:

Fatal Exception: java.lang.IllegalStateException: UiAutomation not connected! at android.app.UiAutomation.throwIfNotConnectedLocked(UiAutomation.java:971) at android.app.UiAutomation.disconnect(UiAutomation.java:237) at android.app.Instrumentation.finish(Instrumentation.java:222) at android.support.test.runner.MonitoringInstrumentation.finish(MonitoringInstrumentation.java:351) at android.support.test.runner.AndroidJUnitRunner.finish(AndroidJUnitRunner.java:405) at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:394) at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1970)

Even i faced the same issue …!

it fixed by doing adb kill-server , adb start-server .