shwenzhang/AndResGuard · error · DirectoryException
DirectoryException
Error message
DirectoryException
What it means
ZipRODirectory's constructor throws DirectoryException when new ZipFile(zipFile) fails with an IOException, i.e. the zip cannot be opened because it is missing, unreadable, or not a valid zip archive.
Solutions
- Verify the zip exists and is readable before constructing: file.exists() && file.canRead().
- Validate the archive is a real zip (e.g. ZipFile-open a probe or check magic bytes PK\\x03\\x04) and re-acquire/rebuild the artifact if corrupt.
- Catch DirectoryException and surface the cause IOException to the user.
Example fix
// before
Directory dir = new ZipRODirectory(apkFile, "res");
// after
if (!apkFile.isFile() || !apkFile.canRead()) throw new IOException("apk missing: " + apkFile);
try {
Directory dir = new ZipRODirectory(apkFile, "res");
} catch (DirectoryException e) {
throw new IOException("invalid zip apk: " + apkFile, e.getCause());
} Defensive patterns
Strategy: try-catch
Validate before calling
if (!zipFile.isFile() || !zipFile.canRead()) throw new IOException("zip missing/unreadable: " + zipFile); Try / catch
try { Directory d = new ZipRODirectory(zipFile, path); } catch (DirectoryException e) { throw new IOException("invalid or unreadable zip: " + zipFile, e.getCause()); } Prevention
- Verify artifact integrity (exists, non-zero size, readable) before opening
- Rebuild/re-download corrupted artifacts instead of retrying the open
- Confirm the input is actually a zip (APK), not an AAB or encrypted file
When it happens
Trigger: new ZipRODirectory(File, String) with a file that does not exist, is locked/corrupt, or is not a real zip (e.g. an encrypted or partially downloaded APK).
Common situations: Pointing the tool at an unsigned/corrupted intermediate APK; a previous build step truncated the file; passing an AAB or non-zip artifact.
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
- DirectoryException
- Can't Generate signed APK. Plz check your v1sign info is…
- Can't Generate signed APK v2. Plz check your v2sign info is…
- Can not found any signed apk file
- can not found the raw apk file to zipalign, path=
AI-assisted analysis of shwenzhang/AndResGuard@e4df245d82 (2026-09-12).
Data as JSON: /api/errors/a9383d83df36af3c.
Report an issue: GitHub.
Appendix: source
Thrown at AndResGuard-core/src/main/java/com/tencent/mm/directory/ZipRODirectory.java:52
public ZipRODirectory(File zipFile) throws DirectoryException {
this(zipFile, "");
}
public ZipRODirectory(ZipFile zipFile) {
this(zipFile, "");
}
public ZipRODirectory(String zipFileName, String path) throws DirectoryException {
this(new File(zipFileName), path);
}
public ZipRODirectory(File zipFile, String path) throws DirectoryException {
super();
try {
mZipFile = new ZipFile(zipFile);
} catch (IOException e) {
throw new DirectoryException(e);
}
mPath = path;
}
public ZipRODirectory(ZipFile zipFile, String path) {
super();
mZipFile = zipFile;
mPath = path;
}
@Override
protected AbstractDirectory createDirLocal(String name) throws DirectoryException {
throw new UnsupportedOperationException();
}
@Override
protected InputStream getFileInputLocal(String name) throws DirectoryException {
try {View on GitHub (pinned to e4df245d82)