MuntashirAkon/AppManager · error · IOException

Could not verify aligned APK file.

Error message

Could not verify aligned APK file.

What it means

ZipAlign.align rewrites the APK with a zip aligner and then verifies the output. If verify() reports the newly written file is not aligned to the requested boundary, it throws this IOException — an internal sanity check that alignment failed silently.

Solutions

  1. Retry alignment with standard parameters (e.g. alignment=4, pageAlignSharedLibs with 16KB/64KB per target)
  2. Verify the input APK is a valid zip/archive readable by ArchiveFile
  3. Update App Manager — could be a zip writer bug fixed upstream
  4. Check available disk space and output path writability

Example fix

// before
ZipAlign.align(in, out, 8, false);
// after
ZipAlign.align(in, out, 4, true); // standard, well-tested parameters
if (!ZipAlign.verify(out, 4, true)) { /* handle alignment failure */ }
Defensive patterns

Strategy: try-catch

Validate before calling

if (!ZipAlign.verify(output, alignment, pageAlignSharedLibs)) {
    // alignment failed; retry with different parameters before shipping
}

Try / catch

try {
    ZipAlign.align(in, out, 4, true);
} catch (IOException e) {
    if (e.getMessage().contains("Could not verify aligned APK")) {
        // retry once or fall back to unaligned handling
    }
}

Prevention

When it happens

Trigger: Calling ZipAlign.align(input, output, alignment, pageAlignSharedLibs) where the produced output file fails verify(output, alignment, pageAlignSharedLibs), e.g. due to a zip-writing bug, unsupported entry types, or disk issues.

Common situations: Aligning APKs with unusual/uncompressed native libraries, mismatched alignment parameters between align and verify calls, very low alignment values or storage problems.

Understand the failure class

Background: Checksum mismatch errors: "checksum verification failed", "digest mismatch", "expected vs actual checksum" — what they mean and how to fix them — this error's family across 41 libraries.

Related errors


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

Appendix: source

Thrown at app/src/main/java/io/github/muntashirakon/AppManager/apk/signing/ZipAlign.java:41

    public static final int ALIGNMENT_4 = 4;

    private static final int ALIGNMENT_PAGE = 4096;

    public static void align(@NonNull File input, @NonNull File output, int alignment, boolean pageAlignSharedLibs)
            throws IOException {
        File dir = output.getParentFile();
        if (!Paths.exists(dir)) {
            dir.mkdirs();
        }

        try (ArchiveFile archive = new ArchiveFile(input);
             ApkFileWriter apkWriter = new ApkFileWriter(output, archive.getInputSources())) {
            apkWriter.setZipAligner(getZipAligner(alignment, pageAlignSharedLibs));
            apkWriter.write();
        }
        if (!verify(output, alignment, pageAlignSharedLibs)) {
            throw new IOException("Could not verify aligned APK file.");
        }
    }

    public static void align(@NonNull File inFile, int alignment, boolean pageAlignSharedLibs) throws IOException {
        File tmp = toTmpFile(inFile);
        tmp.delete();
        try {
            align(inFile, tmp, alignment, pageAlignSharedLibs);
            inFile.delete();
            tmp.renameTo(inFile);
        } catch (IOException e) {
            tmp.delete();
            throw e;
        }
    }

    public static boolean verify(@NonNull File file, int alignment, boolean pageAlignSharedLibs) {
        ArchiveFile zipFile;

View on GitHub (pinned to 0152f468fc)