diff --git a/airtest/core/android/adb.py b/airtest/core/android/adb.py index c5ddae9c..9dd156cf 100644 --- a/airtest/core/android/adb.py +++ b/airtest/core/android/adb.py @@ -20,6 +20,7 @@ from airtest.utils.logger import get_logger from airtest.utils.nbsp import NonBlockingStreamReader from airtest.utils.retry import retries +from airtest.utils.apkparser import APK from airtest.utils.snippet import get_std_encoding, reg_cleanup, split_cmd, make_file_executable LOGGING = get_logger(__name__) @@ -620,7 +621,21 @@ def install_app(self, filepath, replace=False, install_options=None): if replace: install_options.append("-r") cmds = ["install", ] + install_options + [filepath, ] - out = self.cmd(cmds) + try: + out = self.cmd(cmds) + except AdbError as e: + out = repr(e.stderr) + repr(e.stdout) + # If the signatures are inconsistent, uninstall the old version first + if "INSTALL_FAILED_UPDATE_INCOMPATIBLE" in out and replace: + try: + package_name = re.search(r"package (.*?) .*", out).group(1) + except: + # get package name + package_name = APK(filepath).get_package() + self.uninstall_app(package_name) + out = self.cmd(cmds) + else: + raise if re.search(r"Failure \[.*?\]", out): raise AdbShellError("Installation Failure", repr(out)) @@ -716,8 +731,19 @@ def pm_install(self, filepath, replace=False, install_options=None): try: cmds = ["pm", "install", ] + install_options + [device_path] self.shell(cmds) - except: - raise + except AdbError as e: + out = repr(e.stderr) + repr(e.stdout) + # If the signatures are inconsistent, uninstall the old version first + if re.search(r"INSTALL_FAILED_UPDATE_INCOMPATIBLE", out): + try: + package_name = re.search(r"package (.*?) .*", out).group(1) + except: + # get package name + package_name = APK(filepath).get_package() + self.uninstall_app(package_name) + out = self.shell(cmds) + else: + raise finally: # delete apk file self.cmd(["shell", "rm", device_path], timeout=30) diff --git a/airtest/core/android/static/apks/Yosemite.apk b/airtest/core/android/static/apks/Yosemite.apk index a8bc2f2f..da2a29f2 100644 Binary files a/airtest/core/android/static/apks/Yosemite.apk and b/airtest/core/android/static/apks/Yosemite.apk differ diff --git a/airtest/core/android/yosemite.py b/airtest/core/android/yosemite.py index 8c40279b..2480897e 100644 --- a/airtest/core/android/yosemite.py +++ b/airtest/core/android/yosemite.py @@ -1,3 +1,4 @@ +import traceback import warnings from .constant import YOSEMITE_APK, YOSEMITE_PACKAGE from airtest.utils.snippet import on_method_ready @@ -45,6 +46,7 @@ def _install_apk_upgrade(self, apk_path, package): if installed_version is None: raise # If the installation fails, but the phone has an old version, do not force the installation + print(traceback.format_exc()) warnings.warn("Yosemite.apk update failed, please try to reinstall manually(airtest/core/android/static/apks/Yosemite.apk).") @on_method_ready('install_or_upgrade')