版本号
uiautodev 0.10.0
uiautomator2 3.4.0
现象
uiautomator2 在初始化时,尽管目标设备已有相同的u2.jar,还是会重新再次push u2.jar
原因
- BasicUiautomatorServer 在初始化时会start_uiautomator()
- _setup_jar()的过程中会对本地和设备的 jar 包的 md5 值进行对比
- 部分设备里面其实是没有toybox这个工具的,导致获取不到 md5 值(见下图)

建议优化
先尝试用toybox md5sum 获取,获取不到则同 md5 直接获取。
def _check_device_file_hash(self, local_file: Union[str, Path], remote_file: str) -> bool:
""" check if remote file hash is correct """
...
output = self._dev.shell(["toybox", "md5sum", remote_file])
if "not found" in output:
output = self._dev.shell(["md5", remote_file])
return local_md5 in output