Исправление загрузки tools

This commit is contained in:
2025-09-15 16:48:00 +03:00
parent 630ab0d094
commit c1bb2f8845
+55 -18
View File
@@ -30,14 +30,17 @@ class ToolsConfig(BaseModel):
apktool_jar_url: str apktool_jar_url: str
apktool_wrapper_url: str apktool_wrapper_url: str
class XmlNamespaces(BaseModel): class XmlNamespaces(BaseModel):
android: str android: str
app: str app: str
class BaseSection(BaseModel): class BaseSection(BaseModel):
tools: ToolsConfig tools: ToolsConfig
xml_ns: XmlNamespaces xml_ns: XmlNamespaces
class Config(BaseModel): class Config(BaseModel):
base: BaseSection base: BaseSection
patches: dict patches: dict
@@ -88,7 +91,9 @@ def init():
if not (TOOLS / "apktool.jar").exists(): if not (TOOLS / "apktool.jar").exists():
download(conf.base.tools.apktool_jar_url, TOOLS / "apktool.jar") download(conf.base.tools.apktool_jar_url, TOOLS / "apktool.jar")
wrapper = httpx.get(conf.base.tools.apktool_wrapper_url, timeout=30).text wrapper = httpx.get(
conf.base.tools.apktool_wrapper_url, timeout=30, follow_redirects=True
).text
(TOOLS / "apktool").write_text(wrapper, encoding="utf-8") (TOOLS / "apktool").write_text(wrapper, encoding="utf-8")
(TOOLS / "apktool").chmod(0o755) (TOOLS / "apktool").chmod(0o755)
@@ -138,7 +143,18 @@ def select_apk() -> Path:
def decompile(apk: Path): def decompile(apk: Path):
console.print("[yellow]Декомпиляция apk...") console.print("[yellow]Декомпиляция apk...")
run(["java", "-jar", str(TOOLS / "apktool.jar"), "d", "-f", "-o", str(DECOMPILED), str(apk)]) run(
[
"java",
"-jar",
str(TOOLS / "apktool.jar"),
"d",
"-f",
"-o",
str(DECOMPILED),
str(apk),
]
)
def compile(apk: Path, patches: List[Patch]): def compile(apk: Path, patches: List[Patch]):
@@ -147,22 +163,43 @@ def compile(apk: Path, patches: List[Patch]):
aligned = out_apk.with_stem(out_apk.stem + "-aligned") aligned = out_apk.with_stem(out_apk.stem + "-aligned")
signed = out_apk.with_stem(out_apk.stem + "-mod") signed = out_apk.with_stem(out_apk.stem + "-mod")
run(["java", "-jar", str(TOOLS / "apktool.jar"), "b", str(DECOMPILED), "-o", str(out_apk)]) run(
[
"java",
"-jar",
str(TOOLS / "apktool.jar"),
"b",
str(DECOMPILED),
"-o",
str(out_apk),
]
)
run(["zipalign", "-v", "4", str(out_apk), str(aligned)]) run(["zipalign", "-v", "4", str(out_apk), str(aligned)])
run([ run(
"apksigner", "sign", [
"--v1-signing-enabled", "false", "apksigner",
"--v2-signing-enabled", "true", "sign",
"--v3-signing-enabled", "true", "--v1-signing-enabled",
"--ks", "keystore.jks", "false",
"--ks-pass", "file:keystore.pass", "--v2-signing-enabled",
"--out", str(signed), "true",
str(aligned) "--v3-signing-enabled",
]) "true",
"--ks",
"keystore.jks",
"--ks-pass",
"file:keystore.pass",
"--out",
str(signed),
str(aligned),
]
)
with open(DECOMPILED / "apktool.yml", encoding="utf-8") as f: with open(DECOMPILED / "apktool.yml", encoding="utf-8") as f:
meta = yaml.safe_load(f) meta = yaml.safe_load(f)
version_str = " ".join(f"{k}:{v}" for k, v in meta.get("versionInfo", {}).items()) version_str = " ".join(
f"{k}:{v}" for k, v in meta.get("versionInfo", {}).items()
)
with open(MODIFIED / "report.log", "w", encoding="utf-8") as f: with open(MODIFIED / "report.log", "w", encoding="utf-8") as f:
f.write(f"anixart mod {version_str}\n") f.write(f"anixart mod {version_str}\n")
@@ -200,16 +237,16 @@ def build(
with Progress() as progress: with Progress() as progress:
task = progress.add_task("Патчи", total=len(patch_objs)) task = progress.add_task("Патчи", total=len(patch_objs))
for p in patch_objs: for p in patch_objs:
ok = p.apply( ok = p.apply(patch_settings.get(p.name, {}) | conf.get("base", {}))
patch_settings.get(p.name, {}) | conf.get("base", {})
)
progress.console.print(f"{'' if ok else ''} {p.name}") progress.console.print(f"{'' if ok else ''} {p.name}")
progress.advance(task) progress.advance(task)
successes = sum(p.applied for p in patch_objs) successes = sum(p.applied for p in patch_objs)
if successes == len(patch_objs): if successes == len(patch_objs):
compile(apk, patch_objs) compile(apk, patch_objs)
elif successes > 0 and (force or Prompt.ask("Продолжить сборку?", choices=["y", "n"]) == "y"): elif successes > 0 and (
force or Prompt.ask("Продолжить сборку?", choices=["y", "n"]) == "y"
):
compile(apk, patch_objs) compile(apk, patch_objs)
else: else:
console.print("[red]Сборка отменена") console.print("[red]Сборка отменена")