{"record":{"id":"a4ecba7ea3b36d23","repo":"shwenzhang/AndResGuard","slug":"can-not-found-the-raw-apk-file-to-zipalign-path-s","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":"error","filePath":"AndResGuard-core/src/main/java/com/tencent/mm/androlib/ResourceApkBuilder.java","lineNumber":287,"sourceCode":"    //如果不签名就肯定不需要对齐了\n    if (!config.mUseSignAPK) {\n      return;\n    }\n    if (!mSignedApk.exists() && !mSignedWith7ZipApk.exists()) {\n      throw new IOException(\"Can not found any signed apk file\");\n    }\n    if (mSignedApk.exists()) {\n      alignApk(mSignedApk, mAlignedApk);\n    }\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, exists:%b\\n\", before.getAbsolutePath(), before.exists());\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(config.mZipalignPath) ? config.mZipalignPath : TypedValue.COMMAND_ZIPALIGIN;\n    Utils.runCmd(cmd, \"4\", before.getAbsolutePath(), after.getAbsolutePath());\n    if (!after.exists()) {\n      throw new IOException(String.format(\"can not found the aligned apk file, the ZipAlign path is correct? path=%s\",\n          mAlignedApk.getAbsolutePath()\n      ));\n    }\n  }\n\n  private void generalUnsignApk(HashMap<String, Integer> compressData) throws IOException, InterruptedException {\n    System.out.printf(\"General unsigned apk: %s\\n\", mUnSignedApk.getName());\n    File tempOutDir = new File(mOutDir.getAbsolutePath(), TypedValue.UNZIP_FILE_PATH);\n    if (!tempOutDir.exists()) {\n      System.err.printf(\"Missing apk unzip files, path=%s\\n\", tempOutDir.getAbsolutePath());\n      System.exit(-1);","sourceCodeStart":269,"sourceCodeEnd":305,"githubUrl":"https://github.com/shwenzhang/AndResGuard/blob/e4df245d82f27d9a2d0dd108260a3510cbaba849/AndResGuard-core/src/main/java/com/tencent/mm/androlib/ResourceApkBuilder.java#L269-L305","documentation":"alignApk zipaligns the APK at path 'before' into 'after'. If the input APK does not exist on disk, this IOException with the absolute path is thrown. It is a pre-condition guard so that zipalign is never run against a missing file (which would otherwise produce a confusing native command error).","triggerScenarios":"Called from alignApks or buildApkWithV2V3Sign when the raw/signed APK expected at the given path was never produced or was deleted — e.g. the signing or packaging step silently failed, or config points at the wrong output directory.","commonSituations":"A previous build step failed but the pipeline continued; a custom mZipalignPath/outPath configuration points at a directory that does not match where the APK was written; the unsigned APK was removed by a clean task running concurrently.","solutions":["Check earlier build log lines for the failed signing/packaging step and fix its root cause","Verify the APK path printed in the message exists and that your output/outDir configuration matches where the build writes APKs","Re-run the build from a clean state so the unsigned/signed APK is regenerated before zipalign","If zipalign should not be needed, confirm config.mUseSignAPK is set consistently with your pipeline"],"exampleFix":"// before: signing skipped but zipalign attempted with stale path\n// after: verify the file exists before invoking the builder\nFile apk = new File(outDir, \"app-unsigned.apk\");\nif (!apk.exists()) { throw new IllegalStateException(\"unsigned APK missing: \" + apk); }\nandResGuard.build();","handlingStrategy":"try-catch","validationCode":"File apk = new File(expectedApkPath);\nif (!apk.isFile()) throw new IllegalStateException(\"APK to zipalign does not exist: \" + apk.getAbsolutePath());","typeGuard":null,"tryCatchPattern":"try {\n  andResGuard.build();\n} catch (IOException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"can not found the raw apk file to zipalign\")) {\n    throw new IllegalStateException(\"upstream build/signing step did not produce the APK at \" + e.getMessage(), e);\n  }\n  throw e;\n}","preventionTips":["Make sure the signing/packaging step succeeds before alignment (fix earlier log errors)","Keep outDir/zipalign path configuration consistent with where APKs are written","Avoid running clean tasks concurrently with the build","Re-run from a clean state after any failed build so intermediate APKs are regenerated"],"tags":["java","zipalign","apk","io","file"],"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"}