shwenzhang/AndResGuard · critical · java.io.IOException

can not found the raw apk file to zipalign, path=

Error message

can not found the raw apk file to zipalign, path=%s

What it means

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.

Solutions

  1. Verify the raw APK exists at the logged path (the message prints path=%s); fix the preceding packaging step or output directory if missing.
  2. Check AndResGuard Gradle config (sevenZipPath, outDirectory, apk path inputs) for typos or non-existent directories.
  3. Run a clean full build so upstream steps regenerate the intermediate APK.
  4. If a custom pipeline calls alignApk directly, validate before.exists() and fail fast with your own message before invoking it.

Example fix

// before
ResGuard.alignApk(new File(oldApkPath), new File(newApkPath));
// after
File before = new File(oldApkPath);
if (!before.exists()) {
    throw new IllegalStateException("APK missing, run package task first: " + before);
}
ResGuard.alignApk(before, new File(newApkPath));
Defensive patterns

Strategy: validation

Validate before calling

File before = new File(rawApkPath);
if (!before.isFile()) {
    throw new IllegalStateException("raw APK missing, run package task first: " + before.getAbsolutePath());
}

Prevention

When it happens

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

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

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


AI-assisted analysis of shwenzhang/AndResGuard@e4df245d82 (2026-09-12). Data as JSON: /api/errors/e40a15494c631404. Report an issue: GitHub.

Appendix: source

Thrown at AndResGuard-core/src/main/java/com/tencent/mm/androlib/ResourceRepackage.java:171

    LineNumberReader input = new LineNumberReader(ir);
    //如果不读会有问题,被阻塞
    while (input.readLine() != null) {
    }
    //destroy the stream
    pro.waitFor();
    pro.destroy();
  }

  private void alignApk() throws IOException, InterruptedException {
    if (mSignedWith7ZipApk.exists()) {
      alignApk(mSignedWith7ZipApk, mAlignedWith7ZipApk);
    }
  }

  private void alignApk(File before, File after) throws IOException, InterruptedException {
    System.out.printf("zipaligning apk: %s\n", before.getName());
    if (!before.exists()) {
      throw new IOException(String.format("can not found the raw apk file to zipalign, path=%s",
          before.getAbsolutePath()
      ));
    }
    String cmd = Utils.isPresent(zipalignPath) ? zipalignPath : TypedValue.COMMAND_ZIPALIGIN;
    ProcessBuilder pb = new ProcessBuilder(cmd, "4", before.getAbsolutePath(), after.getAbsolutePath());
    Process pro = pb.start();
    //destroy the stream
    pro.waitFor();
    pro.destroy();
  }
}

View on GitHub (pinned to e4df245d82)