|
23 | 23 | from uiautomator2.exceptions import AccessibilityServiceAlreadyRegisteredError, APKSignatureError, HTTPError, \ |
24 | 24 | HTTPTimeoutError, LaunchUiAutomationError, RPCInvalidError, RPCStackOverflowError, RPCUnknownError, \ |
25 | 25 | UiAutomationNotConnectedError, UiObjectNotFoundError |
26 | | -from uiautomator2.utils import is_version_compatiable |
| 26 | +from uiautomator2.utils import with_package_resource |
27 | 27 | from uiautomator2.version import __apk_version__ |
28 | 28 |
|
29 | 29 | logger = logging.getLogger(__name__) |
@@ -236,14 +236,13 @@ def start_uiautomator(self): |
236 | 236 | self._wait_ready() |
237 | 237 |
|
238 | 238 | def _setup_jar(self): |
239 | | - assets_dir = Path(__file__).parent / "assets" |
240 | | - jar_path = assets_dir / "u2.jar" |
241 | | - target_path = "/data/local/tmp/u2.jar" |
242 | | - if self._check_device_file_hash(jar_path, target_path): |
243 | | - logger.debug("file u2.jar already pushed") |
244 | | - else: |
245 | | - logger.debug("push %s -> %s", jar_path, target_path) |
246 | | - self._dev.sync.push(jar_path, target_path, check=True) |
| 239 | + with with_package_resource("assets/u2.jar") as jar_path: |
| 240 | + target_path = "/data/local/tmp/u2.jar" |
| 241 | + if self._check_device_file_hash(jar_path, target_path): |
| 242 | + logger.debug("file u2.jar already pushed") |
| 243 | + else: |
| 244 | + logger.debug("push %s -> %s", jar_path, target_path) |
| 245 | + self._dev.sync.push(jar_path, target_path, check=True) |
247 | 246 |
|
248 | 247 | def _check_device_file_hash(self, local_file: Union[str, Path], remote_file: str) -> bool: |
249 | 248 | """ check if remote file hash is correct """ |
|
0 commit comments