Skip to content

Commit 9cc695c

Browse files
committed
feat: add ability install xapk files
xapk files are zip files containing apk files This adds ability to install them using the same `install` command. Ref: #303
1 parent 409eff6 commit 9cc695c

File tree

2 files changed

+321
-300
lines changed

2 files changed

+321
-300
lines changed

adbe/adb_enhanced.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import tempfile
1010
import threading
1111
import time
12+
import zipfile
1213
from collections.abc import Callable
1314
from enum import Enum
1415
from functools import partial, wraps
@@ -1673,13 +1674,33 @@ def backup_func() -> None:
16731674

16741675

16751676
def perform_install(file_path: str) -> None:
1677+
if not Path(file_path).exists():
1678+
print_error_and_exit(f"File {file_path} does not exist")
1679+
1680+
if file_path.endswith(".xapk"):
1681+
_perform_xapk_install(file_path)
1682+
return
1683+
16761684
print_verbose(f"Installing {file_path}")
16771685
# -r: replace existing application
16781686
result = execute_adb_command2(f"install -r {file_path}")
16791687
if result.return_code != 0:
16801688
print_error(f"Failed to install {file_path}, stderr: {result.stderr}")
16811689

16821690

1691+
# Note this does not handle the obb files, which are deprecated
1692+
# https://android-developers.googleblog.com/2020/11/new-android-app-bundle-and-target-api.html
1693+
def _perform_xapk_install(file_path: str) -> None:
1694+
# Unzip the xapk file
1695+
with tempfile.TemporaryDirectory() as temp_dir:
1696+
print_verbose(f"Unzipping {file_path} to {temp_dir}")
1697+
with zipfile.ZipFile(file_path, 'r') as zip_ref:
1698+
zip_ref.extractall(temp_dir)
1699+
1700+
result = execute_adb_command2(f"install-multiple -r {temp_dir}/*.apk")
1701+
if result.return_code != 0:
1702+
print_error_and_exit(f"Failed to install xapk {file_path}, stderr: {result.stderr}")
1703+
16831704
@ensure_package_exists
16841705
def perform_uninstall(app_name: str, first_user: bool) -> None:
16851706
print_verbose(f"Uninstalling {app_name}")

0 commit comments

Comments
 (0)