使用Apktool重编译APK时遭遇AndroidManifest.xml.orig权限拒绝问题求助
问题背景
我在Kali Linux中尝试编辑APK文件,操作流程如下:
使用Apktool反编译目标APK:
apktool d ed28.apk反编译过程输出正常:
I: Using Apktool 2.6.1-dirty on ed28.apk
I: Loading resource table...
I: Decoding AndroidManifest.xml with resources...
I: Loading resource table from file: /home/mahdi/.local/share/apktool/framework/1.apk
I: Regular manifest package...
I: Decoding file-resources...
I: Decoding values / XMLs...
I: Baksmaling classes.dex...
I: Copying assets and libs...
I: Copying unknown files...
I: Copying original files...编辑完一个smali文件后,执行重编译命令:
apktool b -d -f ed28却触发权限错误:
I: Using Apktool 2.6.1-dirty
I: Smaling smali folder into classes.dex...
ed28/AndroidManifest.xml.orig: Operation not permitted尝试添加
--use-aapt2参数重新编译,错误依旧存在。
解决方案
这个错误是典型的文件权限问题,AndroidManifest.xml.orig是Apktool反编译时生成的备份文件,当前用户没有足够权限对其进行读写操作,你可以按以下步骤逐一尝试解决:
1. 修复或删除问题备份文件
先查看该备份文件的权限状态:ls -l ed28/AndroidManifest.xml.orig如果权限显示当前用户无法读写,直接修改权限:
chmod 644 ed28/AndroidManifest.xml.orig或者直接删除这个备份文件(Apktool编译过程不依赖它,仅作备份用途):
rm ed28/AndroidManifest.xml.orig2. 以管理员权限执行编译命令
Kali Linux中部分目录或文件需要管理员权限才能操作,尝试用sudo运行编译命令:sudo apktool b -d -f ed28若需要使用aapt2工具,就加上对应参数:
sudo apktool b -d -f ed28 --use-aapt23. 清理编译缓存后重试
先删除之前编译生成的build目录,避免旧文件或缓存干扰新的编译流程:rm -rf ed28/build清理完成后再重新执行编译命令。
4. 更新Apktool到稳定版本
你当前使用的2.6.1-dirty版本带有"dirty"标记,说明可能存在未合并的修改或已知bug,建议替换为官方最新稳定版,能避免不少版本相关的兼容性问题。
内容的提问来源于stack exchange,提问作者user13024846

