openatx / uiautomator2

Android Uiautomator2 Python Wrapper
MIT License
6.67k stars 1.42k forks source link

AccessibilityServiceAlreadyRegisteredError #1013

Open huan1936 opened 4 months ago

huan1936 commented 4 months ago

服务已启动的情况下无法初始化 不知道为啥 出现服务没有关闭 导致现在无法初始化

Traceback (most recent call last):
  File "D:\pyCode\other\ttts.py", line 3, in <module>
    d = u2.connect()
  File "D:\pyCode\other\venv\lib\site-packages\uiautomator2\__init__.py", line 1073, in connect
    return connect_usb(serial)
  File "D:\pyCode\other\venv\lib\site-packages\uiautomator2\__init__.py", line 1089, in connect_usb
    return Device(serial)
  File "D:\pyCode\other\venv\lib\site-packages\uiautomator2\__init__.py", line 69, in __init__
    BasicUiautomatorServer.__init__(self, self._dev)
  File "D:\pyCode\other\venv\lib\site-packages\uiautomator2\core.py", line 169, in __init__
    self.start_uiautomator()
  File "D:\pyCode\other\venv\lib\site-packages\uiautomator2\core.py", line 194, in start_uiautomator
    self._wait_ready()
  File "D:\pyCode\other\venv\lib\site-packages\uiautomator2\core.py", line 218, in _wait_ready
    self._wait_app_process_ready(launch_timeout)
  File "D:\pyCode\other\venv\lib\site-packages\uiautomator2\core.py", line 238, in _wait_app_process_ready
    raise AccessibilityServiceAlreadyRegisteredError(output)
uiautomator2.exceptions.AccessibilityServiceAlreadyRegisteredError: [server] INFO: [UiAutomator2Server] Starting Server
java.lang.IllegalStateException: UiAutomationService android.accessibilityservice.IAccessibilityServiceClient$Stub$Proxy@4fe2ce7already registered!
    at android.os.Parcel.createExceptionOrNull(Parcel.java:2381)
    at android.os.Parcel.createException(Parcel.java:2357)
    at android.os.Parcel.readException(Parcel.java:2340)
    at android.os.Parcel.readException(Parcel.java:2282)
    at android.view.accessibility.IAccessibilityManager$Stub$Proxy.registerUiTestAutomationService(IAccessibilityManager.java:739)
    at android.app.UiAutomationConnection.registerUiTestAutomationServiceLocked(UiAutomationConnection.java:456)
    at android.app.UiAutomationConnection.connect(UiAutomationConnection.java:106)
    at android.app.UiAutomation.connect(UiAutomation.java:243)
    at java.lang.reflect.Method.invoke(Native Method)
    at mirror.RefMethod.call(RefMethod.java:63)
    at uiautomator.InstrumentShellWrapper.getUiAutomation(InstrumentShellWrapper.java:97)
    at androidx.test.uiautomator.UiDevice$Api24Impl.getUiAutomationWithRetry(UiDevice.java:1545)
    at androidx.test.uiautomator.UiDevice.getUiAutomation(UiDevice.java:1468)
    at androidx.test.uiautomator.QueryController.<init>(QueryController.java:95)
    at androidx.test.uiautomator.UiDevice.<init>(UiDevice.java:115)
    at androidx.test.uiautomator.UiDevice.getInstance(UiDevice.java:296)
    at com.wetest.uia2.Main.runServer(Main.java:40)
    at com.wetest.uia2.Main.main(Main.java:29)
    at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
    at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:438)
java.lang.IllegalStateException: UiAutomation not connected, UiAutomation@ddd9c79[id=-1, flags=0]
    at android.app.UiAutomation.throwIfNotConnectedLocked(UiAutomation.java:1239)
    at android.app.UiAutomation.getServiceInfo(UiAutomation.java:497)
    at androidx.test.uiautomator.UiDevice.getUiAutomation(UiDevice.java:1482)
    at androidx.test.uiautomator.QueryController.<init>(QueryController.java:95)
    at androidx.test.uiautomator.UiDevice.<init>(UiDevice.java:115)
    at androidx.test.uiautomator.UiDevice.getInstance(UiDevice.java:296)
    at com.wetest.uia2.Main.runServer(Main.java:40)
    at com.wetest.uia2.Main.main(Main.java:29)
    at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
    at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:438)
codeskyblue commented 4 months ago

是否有别的服务也在运行,比如appium?

huan1936 commented 4 months ago

没有别的服务 就是uiautomator2的服务已经启动了 我试了 重新拔插一下设备让uiautomator2的服务连接断开后 就能重新完成初始化了

shaping520 commented 4 months ago

用ps -ef命令查看到新版本使用的是sh -c CLASSPATH=/data/local/tmp/u2.jar app_process / com.wetest.uia2.Main 服务进程,实在不行就在初始化前先检查下这个进程是否存在。 @codeskyblue 大佬,这个u2.jar包的项目是否开源了呢?

Yan0789 commented 3 months ago

是否有别的服务也在运行,比如appium?

微信截图_20240812171744 大神这是什么情况呢