openatx / uiautomator2

Android Uiautomator2 Python Wrapper
MIT License
6.26k stars 1.36k forks source link

多设备操作时提示:UiAutomationNotConnectedError: ({'code': -32001, 'message': 'java.lang.IllegalStateException', 'data': 'java.lang.IllegalStateException: U #932

Closed jacket230 closed 2 months ago

jacket230 commented 6 months ago

用一台电脑,操作两台设备的时候,出现这种错误。如何解决? uiautomator2.exceptions.UiAutomationNotConnectedError: ({'code': -32001, 'message': 'java.lang.IllegalStateException', 'data': 'java.lang.IllegalStateException: UiAutomation not connected!\n\tat android.app.UiAutomation.throwIfNotConnectedLocked(UiAutomation.java:1034)\n\tat android.app.UiAutomation.injectInputEvent(UiAutomation.java:494)\n\tat androidx.test.uiautomator.InteractionController.injectEventSync(InteractionController.java:690)\n\tat androidx.test.uiautomator.InteractionController.touchDown(InteractionController.java:351)\n\tat androidx.test.uiautomator.InteractionController.swipe(InteractionController.java:487)\n\tat androidx.test.uiautomator.InteractionController.swipe(InteractionController.java:460)\n\tat androidx.test.uiautomator.UiDevice.swipe(UiDevice.java:575)\n\tat com.github.uiautomator.stub.AutomatorServiceImpl.swipe(AutomatorServiceImpl.java:247)\n\tat java.lang.reflect.Method.invoke(Native Method)\n\tat com.googlecode.jsonrpc4j.JsonRpcBasicServer.invoke(JsonRpcBasicServer.java:467)\n\tat com.googlecode.jsonrpc4j.JsonRpcBasicServer.handleObject(JsonRpcBasicServer.java:352)\n\tat com.googlecode.jsonrpc4j.JsonRpcBasicServer.handleJsonNodeRequest(JsonRpcBasicServer.java:283)\n\tat com.googlecode.jsonrpc4j.JsonRpcBasicServer.handleRequest(JsonRpcBasicServer.java:251)\n\tat com.github.uiautomator.stub.AutomatorHttpServer.serve(AutomatorHttpServer.java:100)\n\tat fi.iki.elonen.NanoHTTPD.serve(NanoHTTPD.java:2244)\n\tat fi.iki.elonen.NanoHTTPD$HTTPSession.execute(NanoHTTPD.java:945)\n\tat fi.iki.elonen.NanoHTTPD$ClientHandler.run(NanoHTTPD.java:192)\n\tat java.lang.Thread.run(Thread.java:761)\n'}, 'swipe')

codeskyblue commented 6 months ago

Use multiprocess is recommend

jacket230 commented 6 months ago

Use multiprocess is recommend

yes ,i use multiprocess ,but error . uiautomator2.exceptions.UiAutomationNotConnectedError: ({'code': -32001, 'message': 'java.lang.IllegalStateException', 'data': 'java.lang.IllegalStateException: UiAutomation not connected!\

Source code: from multiprocessing import Process if name == 'main':

创建两个子进程对象 Process(target=main, daemon=True, args=('LovefishO',))

process_task_one = Process(target=task_one)
process_task_two = Process(target=task_two)

def task_one(): d = u2.connect_adb_wifi("192.168.2.xxx:5555") d.swipe_ext('up',0.5)

def task_two(): d = u2.connect_adb_wifi("192.168.2.xxx1:5555") d.swipe_ext('up',0.5)

codeskyblue commented 2 months ago

已修复