在aws服务器上运行apktool会导致err = 2 / err = 13

时间:2016-09-11 19:45:42

标签: android amazon-web-services aapt

我正在尝试反编译并重新编译我的aws服务器上的apk。 我正在使用apktool,它似乎在我的本地机器上正常工作。在服务器上认为我能够反编译,但我无法重新编译它,因为我收到此错误:

>> java -jar apktool/apktool.jar b decompiled_apk_folder
I: Using Apktool 2.2.0
I: Checking whether sources has changed...
I: Checking whether resources has changed...
I: Building resources...
Exception in thread "main" brut.androlib.AndrolibException: brut.androlib.AndrolibException: brut.common.BrutException: could not exec: [/tmp/brut_util_Jar_7342825870469849287.tmp, p, --forced-package-id, 127, --min-sdk-version, 16, --target-sdk-version, 21, --version-code, 1, --version-name, 1.1.3, -F, /tmp/APKTOOL5650064046902136421.tmp, -0, arsc, -0, arsc, -I, /root/.local/share/apktool/framework/1.apk, -S, /decompile_apk_folder/res, -M, /decompile_apk_folder/AndroidManifest.xml]
    at brut.androlib.Androlib.buildResourcesFull(Androlib.java:473)
    at brut.androlib.Androlib.buildResources(Androlib.java:407)
    at brut.androlib.Androlib.build(Androlib.java:306)
    at brut.androlib.Androlib.build(Androlib.java:263)
    at brut.apktool.Main.cmdBuild(Main.java:224)
    at brut.apktool.Main.main(Main.java:84)
Caused by: brut.androlib.AndrolibException: brut.common.BrutException: could not exec: [/tmp/brut_util_Jar_7342825870469849287.tmp, p, --forced-package-id, 127, --min-sdk-version, 16, --target-sdk-version, 21, --version-code, 1, --version-name, 1.1.3, -F, /tmp/APKTOOL5650064046902136421.tmp, -0, arsc, -0, arsc, -I, /root/.local/share/apktool/framework/1.apk, -S, /decompile_apk_folder/res, -M, /decompile_apk_folder/AndroidManifest.xml]
    at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.java:439)
    at brut.androlib.Androlib.buildResourcesFull(Androlib.java:459)
    ... 5 more
Caused by: brut.common.BrutException: could not exec: [/tmp/brut_util_Jar_7342825870469849287.tmp, p, --forced-package-id, 127, --min-sdk-version, 16, --target-sdk-version, 21, --version-code, 1, --version-name, 1.1.3, -F, /tmp/APKTOOL5650064046902136421.tmp, -0, arsc, -0, arsc, -I, /root/.local/share/apktool/framework/1.apk, -S, /decompile_apk_folder/res, -M, /decompile_apk_folder/AndroidManifest.xml]
    at brut.util.OS.exec(OS.java:97)
    at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.java:433)
    ... 6 more
Caused by: java.io.IOException: Cannot run program "/tmp/brut_util_Jar_7342825870469849287.tmp": error=2, No such file or directory
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1047)
    at brut.util.OS.exec(OS.java:90)
    ... 7 more
Caused by: java.io.IOException: error=2, No such file or directory
    at java.lang.UNIXProcess.forkAndExec(Native Method)
    at java.lang.UNIXProcess.<init>(UNIXProcess.java:187)
    at java.lang.ProcessImpl.start(ProcessImpl.java:130)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1028)
    ... 8 more

我在服务器上安装了构建工具和aapt的android sdk,并且使用platform-tools和tools目录正确设置了PATH变量。任何帮助将不胜感激。

修改
我也尝试下载一个预先构建的aapt并在参数中提及它:

java -jar apktool/apktool.jar --aapt /absolute/path/to/aapt_dir b decompiled_apk_folder

然后我获得了权限被拒绝异常,但以 root (sudo su - )运行:

Caused by: java.io.IOException: Cannot run program "/absolute/path/to/aapt_dir": error=13, Permission denied
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1047)
    at brut.util.OS.exec(OS.java:90)
    ... 7 more
Caused by: java.io.IOException: error=13, Permission denied
    at java.lang.UNIXProcess.forkAndExec(Native Method)
    at java.lang.UNIXProcess.<init>(UNIXProcess.java:187)
    at java.lang.ProcessImpl.start(ProcessImpl.java:130)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1028)
    ... 8 more

1 个答案:

答案 0 :(得分:0)

Apktool将需要执行的二进制文件(aapt)复制到基于Java环境变量(TMP_DIR)的临时位置,并在完成后将其删除。这似乎是在AWS系统上使用的不良选择。

可以更新Apktool以识别其在Amazon系统上的使用,并将二进制文件放在主文件夹(〜)中,或者您可以手动下载系统的aapt [1]二进制文件(unix)并使用参数{{ 1}}以防止apktool自动执行此操作。

[1] https://github.com/iBotPeaches/Apktool/tree/master/brut.apktool/apktool-lib/src/main/resources/prebuilt/aapt