{"record":{"id":"1eee34e63b817ae4","repo":"MuntashirAkon/AppManager","slug":"could-not-verify-aligned-apk-file","errorCode":null,"errorMessage":"Could not verify aligned APK file.","messagePattern":"Could not verify aligned APK file\\.","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/apk/signing/ZipAlign.java","lineNumber":41,"sourceCode":"\n    public static final int ALIGNMENT_4 = 4;\n\n    private static final int ALIGNMENT_PAGE = 4096;\n\n    public static void align(@NonNull File input, @NonNull File output, int alignment, boolean pageAlignSharedLibs)\n            throws IOException {\n        File dir = output.getParentFile();\n        if (!Paths.exists(dir)) {\n            dir.mkdirs();\n        }\n\n        try (ArchiveFile archive = new ArchiveFile(input);\n             ApkFileWriter apkWriter = new ApkFileWriter(output, archive.getInputSources())) {\n            apkWriter.setZipAligner(getZipAligner(alignment, pageAlignSharedLibs));\n            apkWriter.write();\n        }\n        if (!verify(output, alignment, pageAlignSharedLibs)) {\n            throw new IOException(\"Could not verify aligned APK file.\");\n        }\n    }\n\n    public static void align(@NonNull File inFile, int alignment, boolean pageAlignSharedLibs) throws IOException {\n        File tmp = toTmpFile(inFile);\n        tmp.delete();\n        try {\n            align(inFile, tmp, alignment, pageAlignSharedLibs);\n            inFile.delete();\n            tmp.renameTo(inFile);\n        } catch (IOException e) {\n            tmp.delete();\n            throw e;\n        }\n    }\n\n    public static boolean verify(@NonNull File file, int alignment, boolean pageAlignSharedLibs) {\n        ArchiveFile zipFile;","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/apk/signing/ZipAlign.java#L23-L59","documentation":"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.","triggerScenarios":"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.","commonSituations":"Aligning APKs with unusual/uncompressed native libraries, mismatched alignment parameters between align and verify calls, very low alignment values or storage problems.","solutions":["Retry alignment with standard parameters (e.g. alignment=4, pageAlignSharedLibs with 16KB/64KB per target)","Verify the input APK is a valid zip/archive readable by ArchiveFile","Update App Manager — could be a zip writer bug fixed upstream","Check available disk space and output path writability"],"exampleFix":"// before\nZipAlign.align(in, out, 8, false);\n// after\nZipAlign.align(in, out, 4, true); // standard, well-tested parameters\nif (!ZipAlign.verify(out, 4, true)) { /* handle alignment failure */ }","handlingStrategy":"try-catch","validationCode":"if (!ZipAlign.verify(output, alignment, pageAlignSharedLibs)) {\n    // alignment failed; retry with different parameters before shipping\n}","typeGuard":null,"tryCatchPattern":"try {\n    ZipAlign.align(in, out, 4, true);\n} catch (IOException e) {\n    if (e.getMessage().contains(\"Could not verify aligned APK\")) {\n        // retry once or fall back to unaligned handling\n    }\n}","preventionTips":["Use standard alignment values (4-byte, page-aligned libs)","Ensure sufficient free disk space","Keep the zip-writer library updated"],"tags":["android","apk","zipalign","verification-failed"],"backgroundTag":"checksum-mismatch","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}