{"record":{"id":"04b6909bb891f459","repo":"iBotPeaches/Apktool","slug":"could-not-set-aapt-binary-as-executable","errorCode":null,"errorMessage":"Could not set aapt binary as executable: ","messagePattern":"Could not set aapt binary as executable: ","errorType":"exception","errorClass":"AndrolibException","httpStatus":null,"severity":"error","filePath":"brut.apktool/apktool-lib/src/main/java/brut/androlib/res/AaptManager.java","lineNumber":75,"sourceCode":"            binPath.append(\".exe\");\n        }\n\n        File binFile;\n        try {\n            binFile = Jar.getResourceAsFile(AaptManager.class, binPath.toString(), binName + \"_\");\n        } catch (BrutException ex) {\n            throw new AndrolibException(ex);\n        }\n        setBinaryExecutable(binFile);\n        return binFile;\n    }\n\n    private static void setBinaryExecutable(File binFile) throws AndrolibException {\n        if (!binFile.isFile() || !binFile.canRead()) {\n            throw new AndrolibException(\"Could not read aapt binary: \" + binFile.getPath());\n        }\n        if (!binFile.setExecutable(true)) {\n            throw new AndrolibException(\"Could not set aapt binary as executable: \" + binFile.getPath());\n        }\n    }\n\n    public static int getBinaryVersion(File binFile) throws AndrolibException {\n        setBinaryExecutable(binFile);\n\n        String versionStr = OS.execAndReturn(new String[] { binFile.getPath(), \"version\" });\n        if (versionStr == null) {\n            throw new AndrolibException(\"Could not execute aapt binary at location: \" + binFile.getPath());\n        }\n\n        return getVersionFromString(versionStr);\n    }\n\n    public static int getVersionFromString(String versionStr) throws AndrolibException {\n        if (versionStr.startsWith(\"Android Asset Packaging Tool (aapt) 2:\")) {\n            return 2;\n        }","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/iBotPeaches/Apktool/blob/79b63384d7d7e22917e6ea8b453272da7012515b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/AaptManager.java#L57-L93","documentation":"AndrolibException from AaptManager.setBinaryExecutable() when File.setExecutable(true) returns false — the extracted aapt2 binary could not be marked executable. On POSIX systems this happens with noexec-mounted filesystems or missing ownership; on Windows it indicates ACL problems. Without the executable bit aapt2 cannot be spawned, so resource packing fails before it starts.","triggerScenarios":"TMPDIR or the extraction dir on a filesystem mounted noexec; running as a user without chmod rights on the extracted file (unusual ACL/NFS setups); Windows directories with restrictive ACLs.","commonSituations":"Hardened CI runners that mount /tmp noexec; containers with read-only or noexec tmpfs; NFS-mounted homes with root_squash breaking chmod.","solutions":["Point temp extraction at an exec-allowed directory: mkdir -p /var/tmp/apktool && apktool b app --temp-path /var/tmp/apktool.","Remount the tmp filesystem without noexec, or set TMPDIR to such a location.","Supply your own aapt2 via --aapt pointing at a binary you can execute (e.g. from Android SDK build-tools)."],"exampleFix":"# before (TMPDIR on noexec fs)\napktool b app\n# after\nmkdir -p /var/tmp/apktool\napktool b app --temp-path /var/tmp/apktool\n# alternatively\napktool b app --aapt $ANDROID_HOME/build-tools/34.0.0/aapt2","handlingStrategy":"validation","validationCode":"// Ensure temp dir is on an exec-mounted filesystem\nString[] mount = OS.execAndReturn(new String[]{\"findmnt\", \"-T\", System.getProperty(\"java.io.tmpdir\"), \"-o\", \"OPTIONS\"}).split(\"\\\\s+\");\nif (Arrays.stream(mount).anyMatch(o -> o.contains(\"noexec\"))) {\n    config.setTempDirectory(\"/var/tmp/apktool\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Configure --temp-path to an exec-allowed directory in hardened environments.","Supply an external executable aapt2 via --aapt when temp extraction is restricted."],"tags":["apktool","aapt2","noexec","permissions","build"],"backgroundTag":null,"analyzedSha":"79b63384d7d7e22917e6ea8b453272da7012515b","analyzedAt":"2026-08-14T10:43:28.812Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}