注册 登录
n/program · 2024-06-26 · 440 次浏览
u/iStarCc白银
n/programu/iStarCc · 2024-06-26

想用apktool在Linux上解析安卓软件图标

想用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
登录后参与讨论。
u/udc2b6nr 广告
QuicksilverVPN

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

umami.dnsl.top 了解更多

3 条回复

排序
  1. iStarCc 白银 楼主 2024-06-26

    不太懂apk结构,请问 'hdpi', 'xhdpi', 'xxhdpi', 'xxxhdpi', 'ldpi', 'mdpi', 'anydpi-v26'全吗,图标都在这里吗

    0
  2. James 💯 传奇 MANAGER 2024-06-26

    ldpi nodpi

    0
  3. jzhfg 富可敌国 王者 MANAGER 2024-06-29

    [[2],[2,10]]

    0