想用apktool在Linux上解析安卓软件图标,不知道这样是否还有更简便的方法,Linux系统
```
@staticmethod
def get_apk_icon(apk_path, temp_dir):
try:
if os.path.exists(temp_dir):
shutil.rmtree(temp_dir)
shell_path = os.path.join(os.getcwd(), "app", "shell")
os_version = os.uname().sysname
if os_version == "Darwin":
apktool_path = os.path.join(shell_path, "mac", "bin", "apktool")
else :
apktool_path = os.path.join(shell_path, "linux", "bin", "apktool")
cmd = f"{apktool_path} d {apk_path} -o {temp_dir}"
result = subprocess.run(cmd, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
if result.returncode != 0:
return None
android_manifest_path = os.path.join(temp_dir, "AndroidManifest.xml")
if os.path.exists(android_manifest_path):
with open(android_manifest_path, "r") as f:
content = f.read()
pattern = r'<application[^>]*android:icon="@([^"]*)"'
app_icon = re.findall(pattern, content)
if app_icon:
for dpi in ['hdpi', 'xhdpi', 'xxhdpi', 'xxxhdpi', 'ldpi', 'mdpi', 'anydpi-v26']:
for icon_type in ['.png', '.webp', '.jpg', '.jpeg']:
app_icon_path1 = os.path.join(temp_dir, "res", f"{app_icon[0]}{icon_type}")
app_icon_path2 = os.path.join(temp_dir, "res", f"{app_icon[0].replace('/', f'-{dpi}/', 1)}{icon_type}")
if os.path.exists(app_icon_path1):
return icon_type, app_icon_path1
elif os.path.exists(app_icon_path2):
return icon_type, app_icon_path2
return None, None
return None
except Exception as e:
logger.error(f"Error getting apk icon: {e}")
return None, None
```
0
3

快银 VPN,一键连接全球节点,线路稳定、延迟低。支持 Windows、macOS 等多平台,TUN 全局模式覆盖全部应用流量。无需复杂配置,下载即用。
3 risposte
Ordinamento