Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal Exception in adb logs: UIAutomation not connected #872

Closed
pradeipp opened this issue Mar 17, 2025 · 4 comments
Closed

Fatal Exception in adb logs: UIAutomation not connected #872

pradeipp opened this issue Mar 17, 2025 · 4 comments

Comments

@pradeipp
Copy link

I'm facing this strange issue where the UiAutomator2 driver crashes during session teardown with IllegalStateException: UiAutomation not connected. I'm running tests on real Android devices in CI. This error occurs consistently during the cleanup phase after a test has completed successfully. The issue appears to be a race condition where the UiAutomation connection is terminated before AndroidJUnitRunner can properly clean it up.

  • Appium Version: 2.16.2
  • UiAutomator2 Driver Version: 4.1.2
  • Platform: Android
  • Device: Real Android devices in device farm
  • Android Version: Seen in multiple versions, 25-35

Device log:

--------- beginning of crash
03-17 15:03:51.397  9313  9340 E AndroidRuntime: FATAL EXCEPTION: Instr: androidx.test.runner.AndroidJUnitRunner
03-17 15:03:51.397  9313  9340 E AndroidRuntime: Process: io.appium.uiautomator2.server, PID: 9313
03-17 15:03:51.397  9313  9340 E AndroidRuntime: java.lang.IllegalStateException: UiAutomation not connected, UiAutomation@ced004b[id=-1, flags=0]
03-17 15:03:51.397  9313  9340 E AndroidRuntime: 	at android.app.UiAutomation.throwIfNotConnectedLocked(UiAutomation.java:1239)
03-17 15:03:51.397  9313  9340 E AndroidRuntime: 	at android.app.UiAutomation.disconnect(UiAutomation.java:296)
03-17 15:03:51.397  9313  9340 E AndroidRuntime: 	at android.app.Instrumentation.finish(Instrumentation.java:249)
03-17 15:03:51.397  9313  9340 E AndroidRuntime: 	at androidx.test.runner.MonitoringInstrumentation.finish(MonitoringInstrumentation.java:409)
03-17 15:03:51.397  9313  9340 E AndroidRuntime: 	at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:474)
03-17 15:03:51.397  9313  9340 E AndroidRuntime: 	at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2218)

Appium options:

{
   "platformName": "Android",
   "appium:automationName": "uiautomator2",
   "appium:noSign": true,
   "appium:enforceAppInstall": true,
   "appium:app": "application.apk",
   "appium:adbExecTimeout": 90000,
   "appium:androidInstallTimeout": 90000,
   "appium:autoDismissAlerts": true,  "appium:autoGrantPermissions": true,
   "appium:ignoreHiddenApiPolicyErrors": true,
   "appium:udid": "9FT9K20621905709"
},
@mykola-mokhnach
Copy link
Contributor

mykola-mokhnach commented Mar 17, 2025

I would say such behaviour is expected as we need to make sure that all testing-related processes have been cleaned up properly. Failing to do so may corrupt following tests (e.g. having a random stacktrace in a log is better than a following test fail)

Feel free to improve that code if you know how.

@pradeipp
Copy link
Author

Hi @mykola-mokhnach, Thank you for the prompt response as always.

I frankly don't know much about the project so it'll be a super steep learning curve. And I don't wanna give any false hope either as I'm very underprivileged in terms of free time in my life right now.

I guess I'll just leave this open for now. Thanks once again :)

@mykola-mokhnach
Copy link
Contributor

I've added some fixes into the driver version 4.1.4+
please update your driver and check if there is still this exception present in the logs. Also make sure you properly close your sessions on the client side before starting new ones

@pradeipp
Copy link
Author

Yeah it seems to have been fixed! Thanks a lot @mykola-mokhnach! Will close the ticket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants