MuntashirAkon/AppManager · error · ApkFile.ApkFileException

Failed to read AndroidManifest.xml

Error message

Failed to read AndroidManifest.xml

What it means

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'.

Source

Thrown at app/src/main/java/io/github/muntashirakon/AppManager/apk/ApkUtils.java:170

            try {
                apkSections = com.android.apksig.apk.ApkUtils.findZipSections(apk);
            } catch (ZipFormatException e) {
                throw new ApkFile.ApkFileException("Malformed APK: not a ZIP archive", e);
            }
            List<CentralDirectoryRecord> cdRecords;
            try {
                cdRecords = ZipUtils.parseZipCentralDirectory(apk, apkSections);
            } catch (ApkFormatException e) {
                throw new ApkFile.ApkFileException(e.getMessage(), e);
            }
            try {
                return getAndroidManifestFromApk(
                        cdRecords,
                        apk.slice(0, apkSections.getZipCentralDirectoryOffset()));
            } catch (ApkFormatException e) {
                throw new ApkFile.ApkFileException(e.getMessage(), e);
            } catch (ZipFormatException e) {
                throw new ApkFile.ApkFileException("Failed to read " + MANIFEST_FILE, e);
            }
        } catch (IOException e) {
            throw new ApkFile.ApkFileException(e.getMessage(), e);
        }
    }

    @NonNull
    public static ByteBuffer getManifestFromApk(InputStream apkInputStream) throws ApkFile.ApkFileException {
        try (ZipInputStream zipInputStream = new ZipInputStream(new BufferedInputStream(apkInputStream))) {
            ZipEntry zipEntry;
            while ((zipEntry = zipInputStream.getNextEntry()) != null) {
                if (!zipEntry.getName().equals(MANIFEST_FILE)) {
                    continue;
                }
                ByteArrayOutputStream buffer = new ByteArrayOutputStream();
                byte[] buf = new byte[IoUtils.DEFAULT_BUFFER_SIZE];
                int n;
                while (-1 != (n = zipInputStream.read(buf))) {

View on GitHub (pinned to 0152f468fc)

Solutions

  1. Validate the APK with 'apksigner verify' or 'zip -T' to pinpoint ZIP damage
  2. Re-obtain the APK from a trusted source
  3. Use the stream-based getManifestFromApk variant, which caches the input to a temp file and retries
  4. Check whether any repacking/rezip step corrupted the archive

Example fix

// before
ApkUtils.getManifestFromApk(corruptApkFile);
// after
try {
    manifest = ApkUtils.getManifestFromApk(new FileInputStream(corruptApkFile)); // cached-file retry path
} catch (ApkFile.ApkFileException e) {
    // treat APK as unreadable, re-fetch it
}
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-check with a lenient ZIP tool
Process p = new ProcessBuilder("zip", "-T", apkFile.getAbsolutePath()).start();
if (p.waitFor() != 0) throw new IllegalArgumentException("Corrupt ZIP: " + apkFile);

Try / catch

try {
    return ApkUtils.getManifestFromApk(apkFile);
} catch (ApkFile.ApkFileException e) {
    if (e.getMessage() != null && e.getMessage().contains("Failed to read AndroidManifest.xml")) {
        return ApkUtils.getManifestFromApk(new FileInputStream(apkFile)); // cached retry path
    }
    throw e;
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12). Data as JSON: /api/errors/61cfaa06dcfdfcd7. Report an issue: GitHub.