参考
python版本
截至到写这篇文章的时候, 不要用python3.8
- uiautomator2还不支持python3.8
- 后面的weditor也不支持
- 用python3.7
雷电模拟器版本
设置雷电模拟器的网络为桥接
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200118104558709.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2N1bXRfVFRS,size_16,color_FFFFFF,t_70)
安装uiautomator2
- pip install -U uiautomator2
- python -m uiautomator2 init
-
报错
λ python -m uiautomator2 init [I 200118 10:13:28 init:132] uiautomator2 version: 2.5.3 [I 200118 10:13:28 init:317] Install minicap, minitouch [D 200118 10:13:28 init:53] Use cached assets: C:\Users\mabing\.uiautomator2\cache\minitouch-383030fa57\minitouch [D 200118 10:13:28 init:204] Push to /data/local/tmp/minitouch:0755 [I 200118 10:13:28 init:320] abi:x86 seems to be android emulator, skip install minicap [D 200118 10:13:28 init:222] apk-debug package-info: {'version_name': '2.1.1', 'version_code': '2001001', 'flags': ['DEBUGGABLE', 'HAS_CODE', 'ALLOW_CLEAR_USER_DATA', 'ALLOW_BACKUP'], 'first_install_time': datetime.datetime(2020, 1, 18, 10, 8, 53), 'last_update_time': datetime.datetime(2020, 1, 18, 10, 8, 53), 'signature': 'be1790'} [D 200118 10:13:28 init:223] apk-debug-test package-info: {'version_name': '', 'version_code': '', 'flags': ['DEBUGGABLE', 'HAS_CODE', 'ALLOW_CLEAR_USER_DATA', 'ALLOW_BACKUP'], 'first_install_time': datetime.datetime(2020, 1, 18, 10, 8, 54), 'last_update_time': datetime.datetime(2020, 1, 18, 10, 8, 54), 'signature': '3326b445'} [I 200118 10:13:28 init:335] Already installed com.github.uiautomator apks [D 200118 10:13:28 init:258] Real version: [0, 8, 2], Expect version: [0, 8, 2] [D 200118 10:13:28 init:139] Shell: ('/data/local/tmp/atx-agent', 'server', '--nouia', '-d') [I 200118 10:13:28 init:342] Check atx-agent version Traceback (most recent call last): File "D:\Programs\Python\Python38\lib\runpy.py", line 193, in _run_module_as_main return _run_code(code, main_globals, None, File "D:\Programs\Python\Python38\lib\runpy.py", line 86, in _run_code exec(code, run_globals) File "D:\Programs\Python\Python38\lib\site-packages\uiautomator2\__main__.py", line 247, in <module> main() File "D:\Programs\Python\Python38\lib\site-packages\uiautomator2\__main__.py", line 237, in main actions[args.subparser](args) File "D:\Programs\Python\Python38\lib\site-packages\uiautomator2\__main__.py", line 35, in cmd_init init.install(args.server) File "D:\Programs\Python\Python38\lib\site-packages\uiautomator2\init.py", line 343, in install self.check_atx_agent_version() File "<D:\Programs\Python\Python38\lib\site-packages\decorator.py:decorator-gen-6>", line 2, in check_atx_agent_version File "D:\Programs\Python\Python38\lib\site-packages\retry\api.py", line 73, in retry_decorator return __retry_internal(partial(f, *args, **kwargs), exceptions, tries, delay, max_delay, backoff, jitter, File "D:\Programs\Python\Python38\lib\site-packages\retry\api.py", line 33, in __retry_internal return f() File "D:\Programs\Python\Python38\lib\site-packages\uiautomator2\init.py", line 351, in check_atx_agent_version port = self._device.forward_port(7912) File "D:\Programs\Python\Python38\lib\site-packages\adbutils\__init__.py", line 440, in forward_port for f in self.forward_list(): File "D:\Programs\Python\Python38\lib\site-packages\adbutils\__init__.py", line 276, in forward_list c.check_okay() File "D:\Programs\Python\Python38\lib\site-packages\adbutils\__init__.py", line 146, in check_okay raise AdbError(self.read_string()) adbutils.errors.AdbError: unknown host service
-
要先安装adb
https://dl.google.com/android/repository/platform-tools_r29.0.5-windows.zipD:\tool\platform-tools>adb.exe devices List of devices attached emulator-5554 device
-
再次执行
λ python -m uiautomator2 init [I 200118 10:36:22 init:132] uiautomator2 version: 2.5.3 [I 200118 10:36:22 init:317] Install minicap, minitouch [D 200118 10:36:22 init:53] Use cached assets: C:\Users\mabing\.uiautomator2\cache\minitouch-383030fa57\minitouch [D 200118 10:36:22 init:204] Push to /data/local/tmp/minitouch:0755 [I 200118 10:36:22 init:320] abi:x86 seems to be android emulator, skip install minicap [D 200118 10:36:22 init:222] apk-debug package-info: {'version_name': '2.1.1', 'version_code': '2001001', 'flags': ['DEBUGGABLE', 'HAS_CODE', 'ALLOW_CLEAR_USER_DATA', 'ALLOW_BACKUP'], 'first_install_time': datetime.datetime(2020, 1, 18, 10, 8, 53), 'last_update_time': datetime.datetime(2020, 1, 18, 10, 8, 53), 'signature': '9583887'} [D 200118 10:36:22 init:223] apk-debug-test package-info: {'version_name': '', 'version_code': '', 'flags': ['DEBUGGABLE', 'HAS_CODE', 'ALLOW_CLEAR_USER_DATA', 'ALLOW_BACKUP'], 'first_install_time': datetime.datetime(2020, 1, 18, 10, 8, 54), 'last_update_time': datetime.datetime(2020, 1, 18, 10, 8, 54), 'signature': '9583887'} [I 200118 10:36:22 init:335] Already installed com.github.uiautomator apks [D 200118 10:36:22 init:258] Real version: [0, 8, 2], Expect version: [0, 8, 2] [D 200118 10:36:22 init:139] Shell: ('/data/local/tmp/atx-agent', 'server', '--nouia', '-d') [I 200118 10:36:22 init:342] Check atx-agent version [D 200118 10:36:22 init:352] Forward: local:tcp:62064 -> remote:tcp:7912 [D 200118 10:36:23 init:352] Forward: local:tcp:62064 -> remote:tcp:7912 [D 200118 10:36:23 init:355] atx-agent version 0.8.2 Successfully init AdbDevice(serial=emulator-5554)
-
安装weditor
weditor的issue里提到python 3.8 好像启动不了
- pip install weditor
- python -m weditor
- 报错:
λ python -m weditor
listening on http://192.168.1.100:17310
Traceback (most recent call last):
File “D:\Programs\Python\Python38\lib\runpy.py”, line 193, in run_module_as_main
return run_code(code, main_globals, None,
File “D:\Programs\Python\Python38\lib\runpy.py”, line 86, in run_code
exec(code, run_globals)
File "D:\Programs\Python\Python38\lib\site-packages\weditor_main.py", line 210, in
main()
File "D:\Programs\Python\Python38\lib\site-packages\weditor_main.py", line 206, in main
run_web(args.debug, args.port, open_browser, args.force_quit)
File "D:\Programs\Python\Python38\lib\site-packages\weditor_main.py", line 152, in run_web
application.listen(port)
File “D:\Programs\Python\Python38\lib\site-packages\tornado\web.py”, line 2112, in listen
server.listen(port, address)
File “D:\Programs\Python\Python38\lib\site-packages\tornado\tcpserver.py”, line 152, in listen
self.add_sockets(sockets)
File “D:\Programs\Python\Python38\lib\site-packages\tornado\tcpserver.py”, line 165, in add_sockets
self._handlers[sock.fileno()] = add_accept_handler(
File “D:\Programs\Python\Python38\lib\site-packages\tornado\netutil.py”, line 279, in add_accept_handler
io_loop.add_handler(sock, accept_handler, IOLoop.READ)
File “D:\Programs\Python\Python38\lib\site-packages\tornado\platform\asyncio.py”, line 99, in add_handler
self.asyncio_loop.add_reader(fd, self._handle_events, fd, IOLoop.READ)
File “D:\Programs\Python\Python38\lib\asyncio\events.py”, line 501, in add_reader
raise NotImplementedError
NotImplementedError
启动weditor
- 会自动打开浏览器
λ python -m weditor listening on http://192.168.1.100:17310 [I 200118 13:41:55 web:2246] 304 GET / (::1) 10.74ms [I 200118 13:41:56 web:2246] 304 GET /cdn.jsdelivr.ne
- 填入模拟器ip,点击
Connect
, 点击Dump Hirerarchy