添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

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 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! qing0404 opened this issue May 6, 2019 · 8 comments if uiDevice.info.get('screenOn') != 'true':
报错信息:
File "D:\work\Python37\lib\site-packages\uiautomator2_ init _.py", line 1063, in getattr
return getattr(self. default_session, attr)
File "D:\work\Python37\lib\site-packages\uiautomator2_ init
.py", line 1565, in info
return self.jsonrpc.deviceInfo()
File "D:\work\Python37\lib\site-packages\uiautomator2_ init _.py", line 425, in call
params, http_timeout)
File "D:\work\Python37\lib\site-packages\uiautomator2_ init _.py", line 432, in jsonrpc_retry_call
return self.jsonrpc_call(*args, **kwargs)
File "D:\work\Python37\lib\site-packages\uiautomator2_ init _.py", line 505, in jsonrpc_call
raise err
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.app.UiAutomation.waitForIdle(UiAutomation.java:647)
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.(DeviceInfo.java:51)
at com.github.uiautomator.stub.DeviceInfo.getDeviceInfo(DeviceInfo.java:44)
at com.github.uiautomator.stub.AutomatorServiceImpl.deviceInfo(AutomatorServiceImpl.java:105)
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)

u2:2.10.2,设备:华为mate9pro/安卓9.0

[D 210525 10:02:16 __init__:595] kill process(ps): uiautomator
2021-05-25 10:02:16:962 : [D 210525 10:02:16 __init__:614] uiautomator-v2 is starting ... left: 40.0s
2021-05-25 10:02:17:724 : [D 210525 10:02:17 __init__:595] kill process(ps): uiautomator
2021-05-25 10:02:17:976 : [D 210525 10:02:17 __init__:614] uiautomator-v2 is starting ... left: 39.0s
2021-05-25 10:02:18:407 : [I 210525 10:02:18 __init__:567] restart-uiautomator since "-32001 Jsonrpc error: <java.lang.IllegalStateException> data: java.lang.IllegalStateException: UiAutomation not connected!
2021-05-25 10:02:18:408 :     	at android.app.UiAutomation.throwIfNotConnectedLocked(UiAutomation.java:1116)
2021-05-25 10:02:18:408 :     	at android.app.UiAutomation.setRotation(UiAutomation.java:545)
2021-05-25 10:02:18:408 :     	at androidx.test.uiautomator.InteractionController.setRotationNatural(InteractionController.java:631)
2021-05-25 10:02:18:408 :     	at androidx.test.uiautomator.UiDevice.setOrientationNatural(UiDevice.java:853)
2021-05-25 10:02:18:408 :     	at com.github.uiautomator.stub.AutomatorServiceImpl.setOrientation(AutomatorServiceImpl.java:381)
2021-05-25 10:02:18:408 :     	at java.lang.reflect.Method.invoke(Native Method)
2021-05-25 10:02:18:408 :     	at com.googlecode.jsonrpc4j.JsonRpcBasicServer.invoke(JsonRpcBasicServer.java:467)
2021-05-25 10:02:18:408 :     	at com.googlecode.jsonrpc4j.JsonRpcBasicServer.handleObject(JsonRpcBasicServer.java:352)
2021-05-25 10:02:18:408 :     	at com.googlecode.jsonrpc4j.JsonRpcBasicServer.handleJsonNodeRequest(JsonRpcBasicServer.java:283)
2021-05-25 10:02:18:408 :     	at com.googlecode.jsonrpc4j.JsonRpcBasicServer.handleRequest(JsonRpcBasicServer.java:251)
2021-05-25 10:02:18:408 :     	at com.github.uiautomator.stub.AutomatorHttpServer.serve(AutomatorHttpServer.java:100)
2021-05-25 10:02:18:408 :     	at fi.iki.elonen.NanoHTTPD.serve(NanoHTTPD.java:2244)
2021-05-25 10:02:18:408 :     	at fi.iki.elonen.NanoHTTPD$HTTPSession.execute(NanoHTTPD.java:945)
2021-05-25 10:02:18:408 :     	at fi.iki.elonen.NanoHTTPD$ClientHandler.run(NanoHTTPD.java:192)
2021-05-25 10:02:18:408 :     	at java.lang.Thread.run(Thread.java:784)
2021-05-25 10:02:18:408 :     , method: setOrientation"
2021-05-25 10:02:18:436 : [D 210525 10:02:18 __init__:595] kill process(ps): uiautomator
2021-05-25 10:02:18:679 : [D 210525 10:02:18 __init__:614] uiautomator-v2 is starting ... left: 40.0s
2021-05-25 10:02:18:696 : [D 210525 10:02:18 __init__:649] grant permissions
2021-05-25 10:02:19:108 : [I 210525 10:02:19 __init__:567] restart-uiautomator since "uiautomator2.GatewayError(gateway error, time used 0.0s)"
2021-05-25 10:02:19:166 : [D 210525 10:02:19 __init__:595] kill process(ps): uiautomator
2021-05-25 10:02:19:424 : [D 210525 10:02:19 __init__:649] grant permissions
2021-05-25 10:02:19:456 : [D 210525 10:02:19 __init__:614] uiautomator-v2 is starting ... left: 40.0s
2021-05-25 10:02:19:864 : Process Process-2:
2021-05-25 10:02:19:865 : Traceback (most recent call last):
2021-05-25 10:02:19:865 :   File "/usr/local/lib/python3.7/site-packages/uiautomator2/__init__.py", line 438, in _jsonrpc_retry_call
2021-05-25 10:02:19:865 :     return self._jsonrpc_call(*args, **kwargs)
2021-05-25 10:02:19:865 :   File "/usr/local/lib/python3.7/site-packages/uiautomator2/__init__.py", line 510, in _jsonrpc_call
2021-05-25 10:02:19:865 :     raise err
2021-05-25 10:02:19:865 : uiautomator2.exceptions.UiAutomationNotConnectedError: -32001 Jsonrpc error: <java.lang.IllegalStateException> data: java.lang.IllegalStateException: UiAutomation not connected!
2021-05-25 10:02:19:865 : 	at android.app.UiAutomation.throwIfNotConnectedLocked(UiAutomation.java:1116)
2021-05-25 10:02:19:865 : 	at android.app.UiAutomation.setRotation(UiAutomation.java:545)
2021-05-25 10:02:19:865 : 	at androidx.test.uiautomator.InteractionController.setRotationNatural(InteractionController.java:631)
2021-05-25 10:02:19:865 : 	at androidx.test.uiautomator.UiDevice.setOrientationNatural(UiDevice.java:853)
2021-05-25 10:02:19:865 : 	at com.github.uiautomator.stub.AutomatorServiceImpl.setOrientation(AutomatorServiceImpl.java:381)
2021-05-25 10:02:19:865 : 	at java.lang.reflect.Method.invoke(Native Method)
2021-05-25 10:02:19:865 : 	at com.googlecode.jsonrpc4j.JsonRpcBasicServer.invoke(JsonRpcBasicServer.java:467)
2021-05-25 10:02:19:865 : 	at com.googlecode.jsonrpc4j.JsonRpcBasicServer.handleObject(JsonRpcBasicServer.java:352)
2021-05-25 10:02:19:865 : 	at com.googlecode.jsonrpc4j.JsonRpcBasicServer.handleJsonNodeRequest(JsonRpcBasicServer.java:283)
2021-05-25 10:02:19:865 : 	at com.googlecode.jsonrpc4j.JsonRpcBasicServer.handleRequest(JsonRpcBasicServer.java:251)
2021-05-25 10:02:19:866 : 	at com.github.uiautomator.stub.AutomatorHttpServer.serve(AutomatorHttpServer.java:100)
2021-05-25 10:02:19:866 : 	at fi.iki.elonen.NanoHTTPD.serve(NanoHTTPD.java:2244)
2021-05-25 10:02:19:866 : 	at fi.iki.elonen.NanoHTTPD$HTTPSession.execute(NanoHTTPD.java:945)
2021-05-25 10:02:19:866 : 	at fi.iki.elonen.NanoHTTPD$ClientHandler.run(NanoHTTPD.java:192)
2021-05-25 10:02:19:866 : 	at java.lang.Thread.run(Thread.java:784)
2021-05-25 10:02:19:866 : , method: setOrientation
2021-05-25 10:02:19:866 : 
2021-05-25 10:02:19:866 : During handling of the above exception, another exception occurred:
2021-05-25 10:02:19:866 : 
2021-05-25 10:02:19:866 : Traceback (most recent call last):
2021-05-25 10:02:19:866 :   File "/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/unittest/suite.py", line 163, in _handleClassSetUp
2021-05-25 10:02:19:866 :     setUpClass()
2021-05-25 10:02:19:866 :   File "/Users/ssfanli/iMacNodeAndroid/workspace/p-e09c07a4ae644bbabe4cf69e2e3ebed7/src/utils/ut.py", line 73, in setUpClass
2021-05-25 10:02:19:866 :     cold=cfg.getboolean('RUN', 'cold'))
2021-05-25 10:02:19:866 :   File "/Users/ssfanli/iMacNodeAndroid/workspace/p-e09c07a4ae644bbabe4cf69e2e3ebed7/src/base/app.py", line 45, in start
2021-05-25 10:02:19:866 :     self.d.set_orientation('n')
2021-05-25 10:02:19:866 :   File "/usr/local/lib/python3.7/site-packages/uiautomator2/__init__.py", line 1090, in set_orientation
2021-05-25 10:02:19:866 :     self.jsonrpc.setOrientation(values[1])
2021-05-25 10:02:19:867 :   File "/usr/local/lib/python3.7/site-packages/uiautomator2/__init__.py", line 432, in __call__
2021-05-25 10:02:19:867 :     http_timeout)
2021-05-25 10:02:19:867 :   File "/usr/local/lib/python3.7/site-packages/uiautomator2/__init__.py", line 442, in _jsonrpc_retry_call
2021-05-25 10:02:19:867 :     self.reset_uiautomator(str(e)) # uiautomator可能出问题了,强制重启一下
2021-05-25 10:02:19:867 :   File "/usr/local/lib/python3.7/site-packages/uiautomator2/__init__.py", line 586, in reset_uiautomator
2021-05-25 10:02:19:867 :     depth=depth + 1)
2021-05-25 10:02:19:867 :   File "/usr/local/lib/python3.7/site-packages/uiautomator2/__init__.py", line 586, in reset_uiautomator
2021-05-25 10:02:19:867 :     depth=depth + 1)
2021-05-25 10:02:19:867 :   File "/usr/local/lib/python3.7/site-packages/uiautomator2/__init__.py", line 563, in reset_uiautomator
2021-05-25 10:02:19:867 :     "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",
2021-05-25 10:02:19:867 : OSError: [Errno Uiautomator started failed.] -32001 Jsonrpc error: <java.lang.IllegalStateException> data: java.lang.IllegalStateException: UiAutomation not connected!
2021-05-25 10:02:19:867 : 	at android.app.UiAutomation.throwIfNotConnectedLocked(UiAutomation.java:1116)
2021-05-25 10:02:19:867 : 	at android.app.UiAutomation.setRotation(UiAutomation.java:545)
2021-05-25 10:02:19:867 : 	at androidx.test.uiautomator.InteractionController.setRotationNatural(InteractionController.java:631)
2021-05-25 10:02:19:867 : 	at androidx.test.uiautomator.UiDevice.setOrientationNatural(UiDevice.java:853)
2021-05-25 10:02:19:867 : 	at com.github.uiautomator.stub.AutomatorServiceImpl.setOrientation(AutomatorServiceImpl.java:381)
2021-05-25 10:02:19:867 : 	at java.lang.reflect.Method.invoke(Native Method)
2021-05-25 10:02:19:868 : 	at com.googlecode.jsonrpc4j.JsonRpcBasicServer.invoke(JsonRpcBasicServer.java:467)
2021-05-25 10:02:19:868 : 	at com.googlecode.jsonrpc4j.JsonRpcBasicServer.handleObject(JsonRpcBasicServer.java:352)
2021-05-25 10:02:19:868 : 	at com.googlecode.jsonrpc4j.JsonRpcBasicServer.handleJsonNodeRequest(JsonRpcBasicServer.java:283)
2021-05-25 10:02:19:868 : 	at com.googlecode.jsonrpc4j.JsonRpcBasicServer.handleRequest(JsonRpcBasicServer.java:251)
2021-05-25 10:02:19:868 : 	at com.github.uiautomator.stub.AutomatorHttpServer.serve(AutomatorHttpServer.java:100)
2021-05-25 10:02:19:868 : 	at fi.iki.elonen.NanoHTTPD.serve(NanoHTTPD.java:2244)
2021-05-25 10:02:19:868 : 	at fi.iki.elonen.NanoHTTPD$HTTPSession.execute(NanoHTTPD.java:945)
2021-05-25 10:02:19:868 : 	at fi.iki.elonen.NanoHTTPD$ClientHandler.run(NanoHTTPD.java:192)
2021-05-25 10:02:19:868 : 	at java.lang.Thread.run(Thread.java:784)
2021-05-25 10:02:19:868 : , method: setOrientation: 'https://github.com/openatx/uiautomator2/wiki/Common-issues'

Same issue with the emulator.
The actual error:

[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 ,这个命令才会重新被识别到
这个问题有解决办法吗