From 581530e9c0f034bf0d29fb44beb90bf1022de649 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B8=D0=BA=D1=82=D0=BE=D1=80?= <78488229+viktor138irk@users.noreply.github.com> Date: Mon, 11 May 2026 22:47:59 +0900 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20Android=20=D0=B8=D0=BD=D1=81=D1=82=D1=80=D1=83?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D1=82=D1=8B=20=D1=81=D0=B1=D0=BE=D1=80=D0=BA?= =?UTF-8?q?=D0=B8=20=D0=B8=20=D1=83=D1=81=D1=82=D0=B0=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=BA=D0=B8=20APK?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/android_tools.py | 48 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 backend/android_tools.py diff --git a/backend/android_tools.py b/backend/android_tools.py new file mode 100644 index 0000000..e3199b9 --- /dev/null +++ b/backend/android_tools.py @@ -0,0 +1,48 @@ +import glob +import os +from pathlib import Path + +from backend.shell_runner import run_command + +DATA_DIR = Path(os.getenv('DEVCONSOLE_DATA_DIR', '/var/lib/devconsole')) +PROJECTS_DIR = DATA_DIR / 'projects' + + +def list_devices() -> dict: + return run_command('adb devices -l', PROJECTS_DIR.as_posix(), timeout=60) + + +def find_apks(workspace: str) -> list[str]: + root = Path(workspace).resolve() + patterns = [ + str(root / '**' / 'build' / 'app' / 'outputs' / 'flutter-apk' / '*.apk'), + str(root / '**' / 'build' / 'outputs' / 'apk' / '**' / '*.apk'), + str(root / '**' / '*.apk'), + ] + found: list[str] = [] + for pattern in patterns: + found.extend(glob.glob(pattern, recursive=True)) + return sorted(set(found), key=lambda p: os.path.getmtime(p), reverse=True) + + +def build_android(workspace: str) -> dict: + root = Path(workspace).resolve() + + if (root / 'pubspec.yaml').exists(): + return run_command('flutter build apk --debug', root.as_posix(), timeout=1800) + + gradlew = root / 'gradlew' + if gradlew.exists(): + return run_command('chmod +x ./gradlew && ./gradlew assembleDebug', root.as_posix(), timeout=1800) + + if (root / 'android' / 'gradlew').exists(): + return run_command('cd android && chmod +x ./gradlew && ./gradlew assembleDebug', root.as_posix(), timeout=1800) + + return run_command('gradle assembleDebug', root.as_posix(), timeout=1800) + + +def install_latest_apk(workspace: str) -> dict: + apks = find_apks(workspace) + if not apks: + raise ValueError('APK not found. Build project first.') + return run_command(f'adb install -r "{apks[0]}"', Path(workspace).resolve().as_posix(), timeout=600)