Skip to content

Commit

Permalink
update: Yosemite.apk and If an INSTALL_FAILED_UPDATE_INCOMPATIBLE exc…
Browse files Browse the repository at this point in the history
…eption occurs when installing apk, uninstall it first and then install it

(cherry picked from commit ac0fae1)
  • Loading branch information
yimelia committed Jul 17, 2023
1 parent d6c12ac commit d69b57c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
32 changes: 29 additions & 3 deletions airtest/core/android/adb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand Down
Binary file modified airtest/core/android/static/apks/Yosemite.apk
Binary file not shown.
2 changes: 2 additions & 0 deletions airtest/core/android/yosemite.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import traceback
import warnings
from .constant import YOSEMITE_APK, YOSEMITE_PACKAGE
from airtest.utils.snippet import on_method_ready
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit d69b57c

Please sign in to comment.