From 59133f78af9616444240bc93cb5fca360d122081 Mon Sep 17 00:00:00 2001 From: jkfujr Date: Wed, 18 Mar 2026 02:31:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20EU=20=E6=9C=AC=E5=9C=B0?= =?UTF-8?q?=E5=8C=96=E6=8F=92=E4=BB=B6=20(EU=20Localization=20Plugin)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 优化前置检查逻辑 (check_prerequisites): - 现在优先检查是否传入了 `--eu-bundle` 参数。 - 解决了因缺失 `is_port_eu_rom` 标志导致插件静默跳过的问题,确保用户显式指定资源包时插件必定运行。 2. 增强日志输出 (_replace_eu_apps): - 新增 `_get_apk_version` 方法,利用 aapt2 提取 APK 版本信息。 - 在替换应用时,输出 Target APK 与 EU Bundle APK 的版本号对比(例如 `[Target: x.x -> Bundle: y.y]`),便于排查版本不匹配问题。 --- src/core/modifiers/plugins/eu_localization.py | 37 ++++++++++++++++--- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/src/core/modifiers/plugins/eu_localization.py b/src/core/modifiers/plugins/eu_localization.py index df7067042..dc9340041 100644 --- a/src/core/modifiers/plugins/eu_localization.py +++ b/src/core/modifiers/plugins/eu_localization.py @@ -10,6 +10,8 @@ import shutil import tempfile import zipfile +import subprocess +import re from pathlib import Path from typing import Any, Dict, List, Union @@ -27,6 +29,10 @@ class EULocalizationPlugin(ModifierPlugin): def check_prerequisites(self) -> bool: """Check if EU localization can be applied.""" + # Check if we have an EU bundle (Explicit override) + if getattr(self.ctx, "eu_bundle", None) is not None: + return True + if not getattr(self.ctx, "is_port_eu_rom", False): return False @@ -34,12 +40,28 @@ def check_prerequisites(self) -> bool: if self._is_stock_cn(): return True - # Check if we have an EU bundle - if getattr(self.ctx, "eu_bundle", None) is not None: - return True - return False + def _get_apk_version(self, apk_path: Path) -> str: + """Get APK version name/code using aapt2.""" + aapt2 = getattr(getattr(self.ctx, "tools", None), "aapt2", None) + if not aapt2 or not apk_path.exists(): + return "unknown" + + try: + cmd = [str(aapt2), "dump", "badging", str(apk_path)] + result = subprocess.run(cmd, capture_output=True, text=True, check=True) + + match = re.search(r"versionName='([^']*)'", result.stdout) + version_name = match.group(1) if match else "unknown" + + match_code = re.search(r"versionCode='([^']*)'", result.stdout) + version_code = match_code.group(1) if match_code else "unknown" + + return f"{version_name} ({version_code})" + except Exception: + return "unknown" + def _is_stock_cn(self) -> bool: """Detect if stock ROM is a CN (China) ROM. @@ -333,12 +355,15 @@ def _replace_eu_apps(self, bundle_path: Path): self.logger.info(f"Found {len(bundle_packages)} unique package(s) to process.") # 2. For each unique package, find and remove original app in target ROM - for pkg_name in bundle_packages: + for pkg_name, bundle_apks in bundle_packages.items(): target_apks = self.ctx.syncer.find_apks_by_package(pkg_name, self.ctx.target_dir) if target_apks: + # Log version comparison + target_ver = self._get_apk_version(target_apks[0]) + bundle_ver = self._get_apk_version(bundle_apks[0]) self.logger.info( - f"Replacing EU App: {pkg_name} ({len(target_apks)} instance(s) found)" + f"Replacing EU App: {pkg_name} [Target: {target_ver} -> Bundle: {bundle_ver}]" ) for target_apk in target_apks: