from __future__ import annotations import os import subprocess from pathlib import Path ANDROID_HOME = os.environ.get("ANDROID_HOME", "") BUILD_TOOLS = os.environ.get("ANDROID_BUILD_TOOLS", "35.0.0") JAVA_HOME = os.environ.get("JAVA_HOME", "") class APKWorkflow: def __init__(self, project: str): self.project = Path(project).resolve() def run(self): return { "validate": self.validate(), "compile_resources": self.compile_resources(), "compile_java": self.compile_java(), "dex": self.dex(), "package": self.package(), "zipalign": self.zipalign(), "sign": self.sign() } def validate(self): manifest = self.project / "AndroidManifest.xml" if not manifest.exists(): return { "ok": False, "error": "AndroidManifest.xml missing" } return {"ok": True} def compile_resources(self): aapt2 = Path(ANDROID_HOME) / "build-tools" / BUILD_TOOLS / "aapt2" if not aapt2.exists(): return { "ok": False, "error": "aapt2 missing" } return {"ok": True} def compile_java(self): javac = "javac" try: subprocess.run( [javac, "-version"], check=True, capture_output=True ) return {"ok": True} except Exception as e: return { "ok": False, "error": str(e) } def dex(self): d8 = Path(ANDROID_HOME) / "build-tools" / BUILD_TOOLS / "d8" return { "ok": d8.exists() } def package(self): aapt2 = Path(ANDROID_HOME) / "build-tools" / BUILD_TOOLS / "aapt2" return { "ok": aapt2.exists() } def zipalign(self): exe = Path(ANDROID_HOME) / "build-tools" / BUILD_TOOLS / "zipalign" return { "ok": exe.exists() } def sign(self): exe = Path(ANDROID_HOME) / "build-tools" / BUILD_TOOLS / "apksigner" return { "ok": exe.exists() } if __name__ == "__main__": import json wf = APKWorkflow("android_project") print(json.dumps(wf.run(), indent=2))