uiautomator2.UiAutomationNotConnectedError: -32001 Jsonrpc error: <java.lang.IllegalStateException> data: java.lang.IllegalStateException: UiAutomation not connected!
uiautomator2.UiAutomationNotConnectedError: -32001 Jsonrpc error: <java.lang.IllegalStateException> data: java.lang.IllegalStateException: UiAutomation not connected!
at android.app.UiAutomation.throwIfNotConnectedLocked(UiAutomation.java:1096)
at android.support.test.uiautomator.QueryController.waitForIdle(QueryController.java:532)
at android.support.test.uiautomator.QueryController.waitForIdle(QueryController.java:523)
at android.support.test.uiautomator.QueryController.getCurrentPackageName(QueryController.java:511)
at android.support.test.uiautomator.UiDevice.getCurrentPackageName(UiDevice.java:653)
at com.github.uiautomator.stub.DeviceInfo.getDeviceInfo(DeviceInfo.java:44)
at com.github.uiautomator.stub.AutomatorServiceImpl.deviceInfo(AutomatorServiceImpl.java:105)
at com.googlecode.jsonrpc4j.JsonRpcBasicServer.invoke(JsonRpcBasicServer.java:467)
at com.googlecode.jsonrpc4j.JsonRpcBasicServer.handleObject(JsonRpcBasicServer.java:352)
at com.googlecode.jsonrpc4j.JsonRpcBasicServer.handleJsonNodeRequest(JsonRpcBasicServer.java:283)
at com.googlecode.jsonrpc4j.JsonRpcBasicServer.handleRequest(JsonRpcBasicServer.java:251)
at com.github.uiautomator.stub.AutomatorHttpServer.serve(AutomatorHttpServer.java:100)
[W 210828 16:54:04 __init__:209] [pid:8126] atx-agent has something wrong, auto recovering
[D 210828 16:54:04 __init__:297] [pid:8126] device 13.127.7.244:5555 is online
[I 210828 16:54:04 init:156] uiautomator2 version: 2.16.7
[D 210828 16:54:04 init:296] Real version: [0, 10, 0], Expect version: [0, 10, 0]
[D 210828 16:54:04 init:256] apk-debug package-info: {'package_name': 'com.github.uiautomator', 'version_name': '2.3.3', 'version_code': '2003003', 'flags': ['DEBUGGABLE', 'HAS_CODE', 'ALLOW_CLEAR_USER_DATA', 'ALLOW_BACKUP'], 'first_install_time': datetime.datetime(2021, 8, 27, 17, 14), 'last_update_time': datetime.datetime(2021, 8, 27, 17, 14), 'signature': 'ae17cd86'}
[D 210828 16:54:04 init:257] apk-debug-test package-info: {'package_name': 'com.github.uiautomator.test', 'version_name': '', 'version_code': '', 'flags': ['DEBUGGABLE', 'HAS_CODE', 'ALLOW_CLEAR_USER_DATA', 'ALLOW_BACKUP'], 'first_install_time': datetime.datetime(2021, 8, 27, 17, 14, 4), 'last_update_time': datetime.datetime(2021, 8, 27, 17, 14, 4), 'signature': 'ae17cd86'}
[D 210828 16:54:04 init:167] Shell: ('/data/local/tmp/atx-agent', 'server', '--nouia', '-d', '--addr', '127.0.0.1:7912')
[D 210828 16:54:04 init:397] Forward: local:tcp:37917 -> remote:tcp:7912
[D 210828 16:54:05 init:397] Forward: local:tcp:37917 -> remote:tcp:7912
[D 210828 16:54:05 init:400] atx-agent version 0.10.0
[D 210828 16:54:05 init:403] device wlan ip: 192.168.232.2
[D 210828 16:54:05 __init__:642] [pid:8126] kill process(ps): uiautomator
[D 210828 16:54:05 __init__:664] [pid:8126] uiautomator-v2 is starting ... left: 40.0s
[D 210828 16:54:07 __init__:664] [pid:8126] uiautomator-v2 is starting ... left: 39.0s
[I 210828 16:54:07 __init__:624] [pid:8126] uiautomator back to normal
{'currentPackageName': 'com.android.launcher3', 'displayHeight': 2278, 'displayRotation': 0, 'displaySizeDpX': 425, 'displaySizeDpY': 943, 'displayWidth': 1080, 'productName': 'cloud_arm', 'screenOn': True, 'sdkInt': 26, 'naturalOrientation': True}
[W 210828 16:54:09 __init__:209] [pid:8126] atx-agent has something wrong, auto recovering
[D 210828 16:54:09 __init__:297] [pid:8126] device 13.127.7.244:5555 is online
[I 210828 16:54:10 init:156] uiautomator2 version: 2.16.7
[D 210828 16:54:10 init:296] Real version: [0, 10, 0], Expect version: [0, 10, 0]
[D 210828 16:54:10 init:256] apk-debug package-info: {'package_name': 'com.github.uiautomator', 'version_name': '2.3.3', 'version_code': '2003003', 'flags': ['DEBUGGABLE', 'HAS_CODE', 'ALLOW_CLEAR_USER_DATA', 'ALLOW_BACKUP'], 'first_install_time': datetime.datetime(2021, 8, 27, 17, 14), 'last_update_time': datetime.datetime(2021, 8, 27, 17, 14), 'signature': 'ae17cd86'}
[D 210828 16:54:10 init:257] apk-debug-test package-info: {'package_name': 'com.github.uiautomator.test', 'version_name': '', 'version_code': '', 'flags': ['DEBUGGABLE', 'HAS_CODE', 'ALLOW_CLEAR_USER_DATA', 'ALLOW_BACKUP'], 'first_install_time': datetime.datetime(2021, 8, 27, 17, 14, 4), 'last_update_time': datetime.datetime(2021, 8, 27, 17, 14, 4), 'signature': 'ae17cd86'}
[D 210828 16:54:10 init:167] Shell: ('/data/local/tmp/atx-agent', 'server', '--nouia', '-d', '--addr', '127.0.0.1:7912')
[D 210828 16:54:10 init:397] Forward: local:tcp:37917 -> remote:tcp:7912
[D 210828 16:54:10 init:397] Forward: local:tcp:37917 -> remote:tcp:7912
[D 210828 16:54:11 init:400] atx-agent version 0.10.0
[D 210828 16:54:11 init:403] device wlan ip: 192.168.232.2
[D 210828 16:54:11 __init__:642] [pid:8126] kill process(ps): uiautomator
[D 210828 16:54:12 __init__:664] [pid:8126] uiautomator-v2 is starting ... left: 40.0s
[D 210828 16:54:13 __init__:664] [pid:8126] uiautomator-v2 is starting ... left: 39.0s
[D 210828 16:54:14 __init__:664] [pid:8126] uiautomator-v2 is starting ... left: 38.0s
[W 210828 16:54:14 __init__:209] [pid:8126] atx-agent has something wrong, auto recovering
[D 210828 16:54:14 __init__:297] [pid:8126] device 13.127.7.244:5555 is online
[I 210828 16:54:14 init:156] uiautomator2 version: 2.16.7
[D 210828 16:54:14 init:296] Real version: [0, 10, 0], Expect version: [0, 10, 0]
[D 210828 16:54:14 init:256] apk-debug package-info: {'package_name': 'com.github.uiautomator', 'version_name': '2.3.3', 'version_code': '2003003', 'flags': ['DEBUGGABLE', 'HAS_CODE', 'ALLOW_CLEAR_USER_DATA', 'ALLOW_BACKUP'], 'first_install_time': datetime.datetime(2021, 8, 27, 17, 14), 'last_update_time': datetime.datetime(2021, 8, 27, 17, 14), 'signature': 'ae17cd86'}
[D 210828 16:54:14 init:257] apk-debug-test package-info: {'package_name': 'com.github.uiautomator.test', 'version_name': '', 'version_code': '', 'flags': ['DEBUGGABLE', 'HAS_CODE', 'ALLOW_CLEAR_USER_DATA', 'ALLOW_BACKUP'], 'first_install_time': datetime.datetime(2021, 8, 27, 17, 14, 4), 'last_update_time': datetime.datetime(2021, 8, 27, 17, 14, 4), 'signature': 'ae17cd86'}
[D 210828 16:54:14 init:167] Shell: ('/data/local/tmp/atx-agent', 'server', '--nouia', '-d', '--addr', '127.0.0.1:7912')
[D 210828 16:54:14 init:397] Forward: local:tcp:37917 -> remote:tcp:7912
[D 210828 16:54:15 init:397] Forward: local:tcp:37917 -> remote:tcp:7912
[D 210828 16:54:16 init:400] atx-agent version 0.10.0
[D 210828 16:54:16 init:403] device wlan ip: 192.168.232.2
[I 210828 16:54:16 __init__:607] [pid:8126] restart-uiautomator since "-32001 Jsonrpc error: <java.lang.IllegalStateException> data: java.lang.IllegalStateException: UiAutomation not connected!
at android.app.UiAutomation.throwIfNotConnectedLocked(UiAutomation.java:1043)
at android.app.UiAutomation.waitForIdle(UiAutomation.java:647)
at androidx.test.uiautomator.QueryController.waitForIdle(QueryController.java:532)
at androidx.test.uiautomator.QueryController.waitForIdle(QueryController.java:523)
at androidx.test.uiautomator.UiDevice.waitForIdle(UiDevice.java:621)
at androidx.test.uiautomator.UiDevice.getWindowRoots(UiDevice.java:1096)
at androidx.test.uiautomator.UiDevice.hasObject(UiDevice.java:137)
at androidx.test.uiautomator.Until$2.apply(Until.java:55)
at androidx.test.uiautomator.Until$2.apply(Until.java:52)
at androidx.test.uiautomator.WaitMixin.wait(WaitMixin.java:40)
at androidx.test.uiautomator.WaitMixin.wait(WaitMixin.java:34)
at androidx.test.uiautomator.UiDevice.wait(UiDevice.java:174)
at com.github.uiautomator.stub.AutomatorServiceImpl.waitForExists(AutomatorServiceImpl.java:1055)
at java.lang.reflect.Method.invoke(Native Method)
at com.googlecode.jsonrpc4j.JsonRpcBasicServer.invoke(JsonRpcBasicServer.java:467)
at com.googlecode.jsonrpc4j.JsonRpcBasicServer.handleObject(JsonRpcBasicServer.java:352)
at com.googlecode.jsonrpc4j.JsonRpcBasicServer.handleJsonNodeRequest(JsonRpcBasicServer.java:283)
at com.googlecode.jsonrpc4j.JsonRpcBasicServer.handleRequest(JsonRpcBasicServer.java:251)
at com.github.uiautomator.stub.AutomatorHttpServer.serve(AutomatorHttpServer.java:100)
at fi.iki.elonen.NanoHTTPD.serve(NanoHTTPD.java:2244)
at fi.iki.elonen.NanoHTTPD$HTTPSession.execute(NanoHTTPD.java:945)
at fi.iki.elonen.NanoHTTPD$ClientHandler.run(NanoHTTPD.java:192)
at java.lang.Thread.run(Thread.java:764)
, method: waitForExists"
[D 210828 16:54:16 __init__:642] [pid:8126] kill process(ps): uiautomator
[D 210828 16:54:17 __init__:704] [pid:8126] grant permissions
[D 210828 16:54:19 __init__:664] [pid:8126] uiautomator-v2 is starting ... left: 40.0s
[D 210828 16:54:20 __init__:664] [pid:8126] uiautomator-v2 is starting ... left: 39.0s
[D 210828 16:54:21 __init__:664] [pid:8126] uiautomator-v2 is starting ... left: 37.9s
[W 210828 16:54:21 __init__:209] [pid:8126] atx-agent has something wrong, auto recovering
[D 210828 16:54:21 __init__:297] [pid:8126] device 13.127.7.244:5555 is online
[I 210828 16:54:21 init:156] uiautomator2 version: 2.16.7
[D 210828 16:54:21 init:296] Real version: [0, 10, 0], Expect version: [0, 10, 0]
[D 210828 16:54:21 init:256] apk-debug package-info: {'package_name': 'com.github.uiautomator', 'version_name': '2.3.3', 'version_code': '2003003', 'flags': ['DEBUGGABLE', 'HAS_CODE', 'ALLOW_CLEAR_USER_DATA', 'ALLOW_BACKUP'], 'first_install_time': datetime.datetime(2021, 8, 27, 17, 14), 'last_update_time': datetime.datetime(2021, 8, 27, 17, 14), 'signature': 'ae17cd86'}
[D 210828 16:54:21 init:257] apk-debug-test package-info: {'package_name': 'com.github.uiautomator.test', 'version_name': '', 'version_code': '', 'flags': ['DEBUGGABLE', 'HAS_CODE', 'ALLOW_CLEAR_USER_DATA', 'ALLOW_BACKUP'], 'first_install_time': datetime.datetime(2021, 8, 27, 17, 14, 4), 'last_update_time': datetime.datetime(2021, 8, 27, 17, 14, 4), 'signature': 'ae17cd86'}
[D 210828 16:54:21 init:167] Shell: ('/data/local/tmp/atx-agent', 'server', '--nouia', '-d', '--addr', '127.0.0.1:7912')
[D 210828 16:54:21 init:397] Forward: local:tcp:37917 -> remote:tcp:7912
[D 210828 16:54:22 init:397] Forward: local:tcp:37917 -> remote:tcp:7912
[D 210828 16:54:22 init:397] Forward: local:tcp:37917 -> remote:tcp:7912
[D 210828 16:54:23 init:400] atx-agent version 0.10.0
[D 210828 16:54:23 init:403] device wlan ip: 192.168.232.2
Traceback (most recent call last):
File "/home/ubuntu/.local/lib/python3.6/site-packages/uiautomator2/__init__.py", line 465, in _jsonrpc_retry_call
return self._jsonrpc_call(*args, **kwargs)
File "/home/ubuntu/.local/lib/python3.6/site-packages/uiautomator2/__init__.py", line 537, in _jsonrpc_call
raise err
uiautomator2.exceptions.UiAutomationNotConnectedError: -32001 Jsonrpc error: <java.lang.IllegalStateException> data: java.lang.IllegalStateException: UiAutomation not connected!
at android.app.UiAutomation.throwIfNotConnectedLocked(UiAutomation.java:1043)
at android.app.UiAutomation.waitForIdle(UiAutomation.java:647)
at androidx.test.uiautomator.QueryController.waitForIdle(QueryController.java:532)
at androidx.test.uiautomator.QueryController.waitForIdle(QueryController.java:523)
at androidx.test.uiautomator.UiDevice.waitForIdle(UiDevice.java:621)
at androidx.test.uiautomator.UiDevice.getWindowRoots(UiDevice.java:1096)
at androidx.test.uiautomator.UiDevice.hasObject(UiDevice.java:137)
at androidx.test.uiautomator.Until$2.apply(Until.java:55)
at androidx.test.uiautomator.Until$2.apply(Until.java:52)
at androidx.test.uiautomator.WaitMixin.wait(WaitMixin.java:40)
at androidx.test.uiautomator.WaitMixin.wait(WaitMixin.java:34)
at androidx.test.uiautomator.UiDevice.wait(UiDevice.java:174)
at com.github.uiautomator.stub.AutomatorServiceImpl.waitForExists(AutomatorServiceImpl.java:1055)
at java.lang.reflect.Method.invoke(Native Method)
at com.googlecode.jsonrpc4j.JsonRpcBasicServer.invoke(JsonRpcBasicServer.java:467)
at com.googlecode.jsonrpc4j.JsonRpcBasicServer.handleObject(JsonRpcBasicServer.java:352)
at com.googlecode.jsonrpc4j.JsonRpcBasicServer.handleJsonNodeRequest(JsonRpcBasicServer.java:283)
at com.googlecode.jsonrpc4j.JsonRpcBasicServer.handleRequest(JsonRpcBasicServer.java:251)
at com.github.uiautomator.stub.AutomatorHttpServer.serve(AutomatorHttpServer.java:100)
at fi.iki.elonen.NanoHTTPD.serve(NanoHTTPD.java:2244)
at fi.iki.elonen.NanoHTTPD$HTTPSession.execute(NanoHTTPD.java:945)
at fi.iki.elonen.NanoHTTPD$ClientHandler.run(NanoHTTPD.java:192)
at java.lang.Thread.run(Thread.java:764)
, method: waitForExists
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "index.py", line 318, in <module>
SetMockLocation(1.356297, 103.819838)
File "index.py", line 25, in SetMockLocation
d(description='More options').click() # Clicking the More options button.
File "/home/ubuntu/.local/lib/python3.6/site-packages/uiautomator2/_selector.py", line 150, in click
self.must_wait(timeout=timeout)
File "/home/ubuntu/.local/lib/python3.6/site-packages/uiautomator2/_selector.py", line 344, in must_wait
if not self.wait(exists, timeout):
File "/home/ubuntu/.local/lib/python3.6/site-packages/uiautomator2/_selector.py", line 316, in wait
http_timeout=http_wait)
File "/home/ubuntu/.local/lib/python3.6/site-packages/uiautomator2/__init__.py", line 459, in __call__
http_timeout)
File "/home/ubuntu/.local/lib/python3.6/site-packages/uiautomator2/__init__.py", line 469, in _jsonrpc_retry_call
self.reset_uiautomator(str(e)) # uiautomator可能出问题了,强制重启一下
File "/home/ubuntu/.local/lib/python3.6/site-packages/uiautomator2/__init__.py", line 633, in reset_uiautomator
depth=depth + 1)
File "/home/ubuntu/.local/lib/python3.6/site-packages/uiautomator2/__init__.py", line 633, in reset_uiautomator
depth=depth + 1)
File "/home/ubuntu/.local/lib/python3.6/site-packages/uiautomator2/__init__.py", line 603, in reset_uiautomator
"adb shell am instrument -w -r -e debug false -e class com.github.uiautomator.stub.Stub com.github.uiautomator.test/android.support.test.runner.AndroidJUnitRunner",
OSError: [Errno Uiautomator started failed.] -32001 Jsonrpc error: <java.lang.IllegalStateException> data: java.lang.IllegalStateException: UiAutomation not connected!
at android.app.UiAutomation.throwIfNotConnectedLocked(UiAutomation.java:1043)
at android.app.UiAutomation.waitForIdle(UiAutomation.java:647)
at androidx.test.uiautomator.QueryController.waitForIdle(QueryController.java:532)
at androidx.test.uiautomator.QueryController.waitForIdle(QueryController.java:523)
at androidx.test.uiautomator.UiDevice.waitForIdle(UiDevice.java:621)
at androidx.test.uiautomator.UiDevice.getWindowRoots(UiDevice.java:1096)
at androidx.test.uiautomator.UiDevice.hasObject(UiDevice.java:137)
at androidx.test.uiautomator.Until$2.apply(Until.java:55)
at androidx.test.uiautomator.Until$2.apply(Until.java:52)
at androidx.test.uiautomator.WaitMixin.wait(WaitMixin.java:40)
at androidx.test.uiautomator.WaitMixin.wait(WaitMixin.java:34)
at androidx.test.uiautomator.UiDevice.wait(UiDevice.java:174)
at com.github.uiautomator.stub.AutomatorServiceImpl.waitForExists(AutomatorServiceImpl.java:1055)
at java.lang.reflect.Method.invoke(Native Method)
at com.googlecode.jsonrpc4j.JsonRpcBasicServer.invoke(JsonRpcBasicServer.java:467)
at com.googlecode.jsonrpc4j.JsonRpcBasicServer.handleObject(JsonRpcBasicServer.java:352)
at com.googlecode.jsonrpc4j.JsonRpcBasicServer.handleJsonNodeRequest(JsonRpcBasicServer.java:283)
at com.googlecode.jsonrpc4j.JsonRpcBasicServer.handleRequest(JsonRpcBasicServer.java:251)
at com.github.uiautomator.stub.AutomatorHttpServer.serve(AutomatorHttpServer.java:100)
at fi.iki.elonen.NanoHTTPD.serve(NanoHTTPD.java:2244)
at fi.iki.elonen.NanoHTTPD$HTTPSession.execute(NanoHTTPD.java:945)
at fi.iki.elonen.NanoHTTPD$ClientHandler.run(NanoHTTPD.java:192)
at java.lang.Thread.run(Thread.java:764)
, method: waitForExists: 'https://github.com/openatx/uiautomator2/wiki/Common-issues'
Observed same issue on Android.
2022-01-12 06:20:06,684 [WARNING] retry.api: uiautomator2.GatewayError(gateway error, time used 0.1s), retrying in 3.0 seconds... [D 220112 06:20:09 __init__:697] force reset uiautomator [D 220112 06:20:09 __init__:721] Product-brand: Amazon [D 220112 06:20:14 __init__:740] uiautomator is starting ... [I 220112 06:20:16 __init__:701] uiautomator back to normal [D 220112 06:23:17 __init__:514] UiAutomation not connected, restart uiautomator 2022-01-12 06:23:17,528 [WARNING] retry.api: -32001 Jsonrpc error: <java.lang.IllegalStateException> data: java.lang.IllegalStateException: UiAutomation not connected! at android.app.UiAutomation.throwIfNotConnectedLocked(UiAutomation.java:1034) at android.app.UiAutomation.waitForIdle(UiAutomation.java:638) at android.support.test.uiautomator.QueryController.waitForIdle(QueryController.java:532) at android.support.test.uiautomator.QueryController.waitForIdle(QueryController.java:523) at android.support.test.uiautomator.UiDevice.waitForIdle(UiDevice.java:621) at android.support.test.uiautomator.UiDevice.getWindowRoots(UiDevice.java:1096) at android.support.test.uiautomator.UiDevice.hasObject(UiDevice.java:137) at android.support.test.uiautomator.Until$2.apply(Until.java:55) at android.support.test.uiautomator.Until$2.apply(Until.java:52) at android.support.test.uiautomator.WaitMixin.wait(WaitMixin.java:49) at android.support.test.uiautomator.WaitMixin.wait(WaitMixin.java:34) at android.support.test.uiautomator.UiDevice.wait(UiDevice.java:174) at com.github.uiautomator.stub.AutomatorServiceImpl.waitForExists(AutomatorServiceImpl.java:986) at java.lang.reflect.Method.invoke(Native Method) at com.googlecode.jsonrpc4j.JsonRpcBasicServer.invoke(JsonRpcBasicServer.java:467) at com.googlecode.jsonrpc4j.JsonRpcBasicServer.handleObject(JsonRpcBasicServer.java:352) at com.googlecode.jsonrpc4j.JsonRpcBasicServer.handleJsonNodeRequest(JsonRpcBasicServer.java:283) at com.googlecode.jsonrpc4j.JsonRpcBasicServer.handleRequest(JsonRpcBasicServer.java:251) at com.github.uiautomator.stub.AutomatorHttpServer.serve(AutomatorHttpServer.java:100) at fi.iki.elonen.NanoHTTPD.serve(NanoHTTPD.java:2244) at fi.iki.elonen.NanoHTTPD$HTTPSession.execute(NanoHTTPD.java:945) at fi.iki.elonen.NanoHTTPD$ClientHandler.run(NanoHTTPD.java:192) at java.lang.Thread.run(Thread.java:761) , method: waitForExists, retrying in 3.5 seconds...
同样遇到这个问题,长时间运行之后出现,莫名就断开
1.adb shell 进程还在,重启进程没有效果
2.目前只有执行python3 -m uiautomator2 init ,这个命令才会重新被识别到
这个问题有解决办法吗