shwenzhang/AndResGuard · error

Could not find old mapping file

Error message

Could not find old mapping file %s

What it means

processOldMappingFile wraps its FileReader construction and, if the file cannot be opened (FileNotFoundException), rethrows this IOException naming the absolute path. This is a second, defensive check after readOldMapping's exists() test — it covers races and permission/open failures between the exists() check and the open, or when exists() passed but the path is a directory.

Solutions

  1. Re-run the build ensuring the mapping file still exists and is a regular readable file at the configured path
  2. Check that the path is a file, not a directory, and that the running user has read permission
  3. If the file is generated by a prior task, serialize the pipeline so nothing deletes it mid-run

Example fix

// before
mOldMappingFile = new File("build/outputs/mapping"); // directory, not the file
// after
mOldMappingFile = new File("build/outputs/mapping/release/mapping.txt");
Defensive patterns

Strategy: try-catch

Validate before calling

java.io.File f = new java.io.File(mappingPath);
if (!f.exists() || !f.isFile() || !f.canRead()) {
  throw new IllegalStateException("mapping file must be a readable regular file: " + f.getAbsolutePath());
}

Try / catch

try {
  new Configuration(configFile, ...);
} catch (IOException e) {
  if (e.getMessage().startsWith("Could not find old mapping file")) {
    // re-check that the file was not deleted/concurrently modified between config parse and read
  }
  throw e;
}

Prevention

When it happens

Trigger: Opening mOldMappingFile with new FileReader(mOldMappingFile) throws FileNotFoundException — the mapping file was deleted between the exists() check and the read, is actually a directory, or is unreadable due to permissions on some filesystems.

Common situations: Concurrent CI jobs cleaning build outputs while AndResGuard runs; a <keepmapping> path pointing at a directory instead of mapping.txt; sandboxed environments denying read access.

Understand the failure class

Background: "open() failed", "failed to open file", "cannot create file" — what a file open error means and how to fix it — this error's family across 42 libraries.

Related errors


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

Appendix: source

Thrown at AndResGuard-core/src/main/java/com/tencent/mm/resourceproguard/Configuration.java:468

      throw new IOException(String.format("the old mapping file do not exit, raw path= %s\n",
          mOldMappingFile.getAbsolutePath()
      ));
    }
    processOldMappingFile();
    System.out.printf("you are using the keepmapping mode to proguard resouces: old mapping path:%s\n",
        mOldMappingFile.getAbsolutePath()
    );
  }

  private void processOldMappingFile() throws IOException {
    mOldResMapping.clear();
    mOldFileMapping.clear();

    FileReader fr;
    try {
      fr = new FileReader(mOldMappingFile);
    } catch (FileNotFoundException ex) {
      throw new IOException(String.format("Could not find old mapping file %s", mOldMappingFile.getAbsolutePath()));
    }
    BufferedReader br = new BufferedReader(fr);
    try {
      String line = br.readLine();

      while (line != null) {
        if (line.length() > 0) {
          Matcher mat = MAP_PATTERN.matcher(line);

          if (mat.find()) {
            String nameAfter = mat.group(2);
            String nameBefore = mat.group(1);
            nameAfter = nameAfter.trim();
            nameBefore = nameBefore.trim();

            //如果有这个的话,那就是mOldFileMapping
            if (line.contains("/")) {
              mOldFileMapping.put(nameBefore, nameAfter);

View on GitHub (pinned to e4df245d82)