pxb1988/dex2jar · error · IOException
the src file not a .dex or zip file
Error message
the src file not a .dex or zip file
What it means
ZipUtil.readDex(byte[]) throws IOException as its final fallback when the input bytes match neither the 'dex' magic nor the 'PK' zip prefix, so there is no supported way to obtain classes.dex from the data. Only raw dex bytes and zip containers are accepted.
Solutions
- Verify the file type with magic bytes (file command) before calling readDex.
- Decompress if the content is gzip/deflate, then retry.
- Fix the download path if you received HTML/text instead of a binary artifact.
- For non-dex binaries (.so/.odex/.vdex), use an appropriate converter first or pass real dex bytes.
Example fix
// before
byte[] dex = ZipUtil.readDex(mysteryBytes);
// after
String magic = new String(mysteryBytes, 0, 3, StandardCharsets.ISO_8859_1);
if (!magic.startsWith("dex") && !magic.startsWith("PK")) {
throw new IllegalArgumentException("not a dex/zip: magic=" + magic);
}
byte[] dex = ZipUtil.readDex(mysteryBytes); Defensive patterns
Strategy: validation
Validate before calling
String magic = data.length >= 3 ? new String(data, 0, 3, StandardCharsets.ISO_8859_1) : "";
if (!magic.startsWith("dex") && !magic.startsWith("PK")) {
throw new IllegalArgumentException("readDex requires dex/zip, got magic=" + magic);
} Type guard
static boolean isDexOrZip(byte[] d) {
return d != null && d.length >= 3 &&
(new String(d, 0, 3, StandardCharsets.ISO_8859_1).startsWith("dex") ||
new String(d, 0, 2, StandardCharsets.ISO_8859_1).equals("PK"));
} Try / catch
try {
byte[] dex = ZipUtil.readDex(data);
} catch (IOException e) {
LOG.error("unsupported input format: " + e.getMessage());
} Prevention
- Check magic bytes before invoking dex tooling
- Validate downloads (status code, content-type, size) before processing
- Decompress compressed artifacts before calling readDex
- Route .so/.odex/.vdex files to converters, not the dex reader
When it happens
Trigger: Calling ZipUtil.readDex on data whose first bytes are not 'dex' or 'PK' — ELF shared libraries, gzip streams, XML resources, HTML error pages from failed downloads.
Common situations: Passing an .odex/.vdex or lib*.so file where a dex was intended; a gzip-compressed dex not decompressed first; a download that saved an HTML error page instead of the APK.
Understand the failure class
Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.
Related errors
- File too small to be a dex/zip
- Can not find classes.dex in zip file
- The source file is not a .dex or .zip file
- File too small to be a dex/zip
- Can not find classes.dex in zip file
AI-assisted analysis of pxb1988/dex2jar@b5bda4fb49 (2026-09-08).
Data as JSON: /api/errors/75100608ad475d0a.
Report an issue: GitHub.
Appendix: source
Thrown at dex-reader/src/main/java/com/googlecode/d2j/reader/zip/ZipUtil.java:89
* @throws IOException
*/
public static byte[] readDex(byte[] data) throws IOException {
if (data.length < 3) {
throw new IOException("File too small to be a dex/zip");
}
if ("dex".equals(new String(data, 0, 3, StandardCharsets.ISO_8859_1))) {// dex
return data;
} else if ("PK".equals(new String(data, 0, 2, StandardCharsets.ISO_8859_1))) {// ZIP
try (ZipFile zipFile = new ZipFile(data)) {
ZipEntry classes = zipFile.findFirstEntry("classes.dex");
if (classes != null) {
return toByteArray(zipFile.getInputStream(classes));
} else {
throw new IOException("Can not find classes.dex in zip file");
}
}
}
throw new IOException("the src file not a .dex or zip file");
}
}
View on GitHub (pinned to b5bda4fb49)