{"record":{"id":"61cfaa06dcfdfcd7","repo":"MuntashirAkon/AppManager","slug":"failed-to-read-androidmanifest-xml","errorCode":null,"errorMessage":"Failed to read AndroidManifest.xml","messagePattern":"Failed to read AndroidManifest\\.xml","errorType":"exception","errorClass":"ApkFile.ApkFileException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/apk/ApkUtils.java","lineNumber":170,"sourceCode":"            try {\n                apkSections = com.android.apksig.apk.ApkUtils.findZipSections(apk);\n            } catch (ZipFormatException e) {\n                throw new ApkFile.ApkFileException(\"Malformed APK: not a ZIP archive\", e);\n            }\n            List<CentralDirectoryRecord> cdRecords;\n            try {\n                cdRecords = ZipUtils.parseZipCentralDirectory(apk, apkSections);\n            } catch (ApkFormatException e) {\n                throw new ApkFile.ApkFileException(e.getMessage(), e);\n            }\n            try {\n                return getAndroidManifestFromApk(\n                        cdRecords,\n                        apk.slice(0, apkSections.getZipCentralDirectoryOffset()));\n            } catch (ApkFormatException e) {\n                throw new ApkFile.ApkFileException(e.getMessage(), e);\n            } catch (ZipFormatException e) {\n                throw new ApkFile.ApkFileException(\"Failed to read \" + MANIFEST_FILE, e);\n            }\n        } catch (IOException e) {\n            throw new ApkFile.ApkFileException(e.getMessage(), e);\n        }\n    }\n\n    @NonNull\n    public static ByteBuffer getManifestFromApk(InputStream apkInputStream) throws ApkFile.ApkFileException {\n        try (ZipInputStream zipInputStream = new ZipInputStream(new BufferedInputStream(apkInputStream))) {\n            ZipEntry zipEntry;\n            while ((zipEntry = zipInputStream.getNextEntry()) != null) {\n                if (!zipEntry.getName().equals(MANIFEST_FILE)) {\n                    continue;\n                }\n                ByteArrayOutputStream buffer = new ByteArrayOutputStream();\n                byte[] buf = new byte[IoUtils.DEFAULT_BUFFER_SIZE];\n                int n;\n                while (-1 != (n = zipInputStream.read(buf))) {","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/apk/ApkUtils.java#L152-L188","documentation":"After locating ZIP sections and central directory records, getManifestFromApk calls getAndroidManifestFromApk to extract AndroidManifest.xml; a ZipFormatException while reading the manifest entry is rethrown as ApkFileException with 'Failed to read AndroidManifest.xml'.","triggerScenarios":"The APK's ZIP central directory parses but reading/decoding the AndroidManifest.xml entry fails with ZipFormatException (corrupt local file header, bad offsets, or resource-based input path).","commonSituations":"Partially corrupted APK where the central directory is intact but entry data is damaged; APK modified/repacked with broken ZIP structure; unusual ZIP layouts from aggressive packing tools.","solutions":["Validate the APK with 'apksigner verify' or 'zip -T' to pinpoint ZIP damage","Re-obtain the APK from a trusted source","Use the stream-based getManifestFromApk variant, which caches the input to a temp file and retries","Check whether any repacking/rezip step corrupted the archive"],"exampleFix":"// before\nApkUtils.getManifestFromApk(corruptApkFile);\n// after\ntry {\n    manifest = ApkUtils.getManifestFromApk(new FileInputStream(corruptApkFile)); // cached-file retry path\n} catch (ApkFile.ApkFileException e) {\n    // treat APK as unreadable, re-fetch it\n}","handlingStrategy":"try-catch","validationCode":"// pre-check with a lenient ZIP tool\nProcess p = new ProcessBuilder(\"zip\", \"-T\", apkFile.getAbsolutePath()).start();\nif (p.waitFor() != 0) throw new IllegalArgumentException(\"Corrupt ZIP: \" + apkFile);","typeGuard":null,"tryCatchPattern":"try {\n    return ApkUtils.getManifestFromApk(apkFile);\n} catch (ApkFile.ApkFileException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"Failed to read AndroidManifest.xml\")) {\n        return ApkUtils.getManifestFromApk(new FileInputStream(apkFile)); // cached retry path\n    }\n    throw e;\n}","preventionTips":["Re-obtain APKs from trusted sources; discard corrupt ones","Avoid repacking steps that rewrite the ZIP with non-standard tools","Prefer the stream-based API which caches to a stable temp file"],"tags":["apk","zip","manifest"],"backgroundTag":"file-read-failed","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}