{"record":{"id":"e40a15494c631404","repo":"shwenzhang/AndResGuard","slug":"can-not-found-the-raw-apk-file-to-zipalign-path-s-e40a15","errorCode":null,"errorMessage":"can not found the raw apk file to zipalign, path=%s","messagePattern":"can not found the raw apk file to zipalign, path=(.+?)","errorType":"exception","errorClass":"java.io.IOException","httpStatus":null,"severity":"critical","filePath":"AndResGuard-core/src/main/java/com/tencent/mm/androlib/ResourceRepackage.java","lineNumber":171,"sourceCode":"    LineNumberReader input = new LineNumberReader(ir);\n    //如果不读会有问题，被阻塞\n    while (input.readLine() != null) {\n    }\n    //destroy the stream\n    pro.waitFor();\n    pro.destroy();\n  }\n\n  private void alignApk() throws IOException, InterruptedException {\n    if (mSignedWith7ZipApk.exists()) {\n      alignApk(mSignedWith7ZipApk, mAlignedWith7ZipApk);\n    }\n  }\n\n  private void alignApk(File before, File after) throws IOException, InterruptedException {\n    System.out.printf(\"zipaligning apk: %s\\n\", before.getName());\n    if (!before.exists()) {\n      throw new IOException(String.format(\"can not found the raw apk file to zipalign, path=%s\",\n          before.getAbsolutePath()\n      ));\n    }\n    String cmd = Utils.isPresent(zipalignPath) ? zipalignPath : TypedValue.COMMAND_ZIPALIGIN;\n    ProcessBuilder pb = new ProcessBuilder(cmd, \"4\", before.getAbsolutePath(), after.getAbsolutePath());\n    Process pro = pb.start();\n    //destroy the stream\n    pro.waitFor();\n    pro.destroy();\n  }\n}\n","sourceCodeStart":153,"sourceCodeEnd":183,"githubUrl":"https://github.com/shwenzhang/AndResGuard/blob/e4df245d82f27d9a2d0dd108260a3510cbaba849/AndResGuard-core/src/main/java/com/tencent/mm/androlib/ResourceRepackage.java#L153-L183","documentation":"AndResGuard throws this IOException in alignApk when the input APK file it is about to pass to the zipalign tool does not exist on disk. The path comes from the preceding build step, so this means the earlier packaging step failed or wrote its output elsewhere. The build aborts before zipalign can run.","triggerScenarios":"Calling alignApk(before, after) with a `before` File whose absolute path does not exist — e.g. the unpacked/raw APK was never produced, was deleted by a clean task, or a custom output directory / `apkFolderPath` / 7zip path is misconfigured so the raw APK lands at a different path.","commonSituations":"Wrong output directory in Gradle config; a previous step (package/buildApk) silently failed; antivirus or CI clean removed the intermediate APK; user overrode zipalignPath/7zipPath pointing at wrong locations and a custom pipeline passes a stale path.","solutions":["Verify the raw APK exists at the logged path (the message prints path=%s); fix the preceding packaging step or output directory if missing.","Check AndResGuard Gradle config (sevenZipPath, outDirectory, apk path inputs) for typos or non-existent directories.","Run a clean full build so upstream steps regenerate the intermediate APK.","If a custom pipeline calls alignApk directly, validate before.exists() and fail fast with your own message before invoking it."],"exampleFix":"// before\nResGuard.alignApk(new File(oldApkPath), new File(newApkPath));\n// after\nFile before = new File(oldApkPath);\nif (!before.exists()) {\n    throw new IllegalStateException(\"APK missing, run package task first: \" + before);\n}\nResGuard.alignApk(before, new File(newApkPath));","handlingStrategy":"validation","validationCode":"File before = new File(rawApkPath);\nif (!before.isFile()) {\n    throw new IllegalStateException(\"raw APK missing, run package task first: \" + before.getAbsolutePath());\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always run the full Gradle pipeline (assemble + resguard task) instead of calling alignApk manually.","Log and verify intermediate artifact paths in CI before the resguard step.","Keep sevenZip/zipalign paths in config pointing at existing binaries."],"tags":["apk","zipalign","file-not-found","build"],"backgroundTag":"file-not-found","analyzedSha":"e4df245d82f27d9a2d0dd108260a3510cbaba849","analyzedAt":"2026-09-12T17:49:07.798Z","contentChangedAt":"2026-09-12T17:49:07.798Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}