{"record":{"id":"f47060dc62ef3411","repo":"iBotPeaches/Apktool","slug":"could-not-execute-aapt-binary-at-location","errorCode":null,"errorMessage":"Could not execute aapt binary at location: ","messagePattern":"Could not execute aapt binary at location: ","errorType":"exception","errorClass":"AndrolibException","httpStatus":null,"severity":"error","filePath":"brut.apktool/apktool-lib/src/main/java/brut/androlib/res/AaptManager.java","lineNumber":84,"sourceCode":"        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        }\n        if (versionStr.startsWith(\"Android Asset Packaging Tool (aapt) 2.\")) {\n            return 2; // Prior to Android SDK 26.0.2\n        }\n        if (versionStr.startsWith(\"Android Asset Packaging Tool, v0.\")) {\n            return 1;\n        }\n        throw new AndrolibException(\"Could not identify aapt binary version: \" + versionStr);\n    }\n}","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/iBotPeaches/Apktool/blob/79b63384d7d7e22917e6ea8b453272da7012515b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/AaptManager.java#L66-L102","documentation":"AndrolibException from AaptManager.getBinaryVersion() when OS.execAndReturn([bin, \"version\"]) returns null, meaning the aapt binary could not be executed at all. This is raised while validating a custom --aapt binary (or the bundled one) before a build: the version probe subprocess failed to start or produced no output, so apktool cannot confirm it is aapt2.","triggerScenarios":"Passing --aapt /path/to/aapt2 where the file is not executable (setExecutable failed or perms changed), the binary is for the wrong architecture (e.g. x86_64 binary on arm64 without Rosetta), glibc is too old for the binary, or the path does not exist.","commonSituations":"Custom aapt2 copied without preserving the exec bit; running a bundled linux x86_64 aapt2 on arm64 hardware; minimal containers missing libc++/glibc versions required by newer build-tools.","solutions":["Verify manually: `/path/to/aapt2 version` — fix whatever it reports (chmod +x, install libc, use correct arch).","Drop --aapt and let apktool use its bundled aapt2, which matches supported platforms.","On Apple Silicon, ensure Rosetta 2 is installed if using an x86_64 aapt2, or use the universal build-tools binary."],"exampleFix":"# before\napktool b app --aapt ./aapt2   # not executable\n# after\nchmod +x ./aapt2 && ./aapt2 version\napktool b app --aapt ./aapt2","handlingStrategy":"validation","validationCode":"if (!aaptFile.canExecute() || OS.execAndReturn(new String[]{aaptFile.getPath(), \"version\"}) == null) {\n    throw new IllegalStateException(\"aapt binary not executable on this host: \" + aaptFile);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Probe custom binaries with `binary version` before handing them to apktool.","Match the aapt2 architecture to the host (or install Rosetta on Apple Silicon)."],"tags":["apktool","aapt","subprocess","build","environment"],"backgroundTag":null,"analyzedSha":"79b63384d7d7e22917e6ea8b453272da7012515b","analyzedAt":"2026-08-14T10:43:28.812Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}