pxb1988/dex2jar · error · IOException

Can not find classes.dex in zip file

Error message

Can not find classes.dex in zip file

What it means

ZipUtil.readDex(byte[]) throws IOException when the input is a valid ZIP (PK prefix) but no entry named exactly "classes.dex" exists inside it. The method's contract is to return the raw bytes of classes.dex, so its absence is fatal.

Solutions

  1. Use MultiDexFileReader.open(bytes) instead — it collects all classes*.dex entries.
  2. Inspect the zip entries (zipFile entries list) to find the actual dex name.
  3. Unpack the APK and pass the extracted classes.dex bytes directly as a raw dex (the dex branch returns data as-is).
  4. If the APK is packed, dump runtime dex files and feed those.

Example fix

// before
byte[] dex = ZipUtil.readDex(apkBytes); // fails if no classes.dex
// after
BaseDexFileReader r = MultiDexFileReader.open(apkBytes); // handles multi-dex
Defensive patterns

Strategy: try-catch

Validate before calling

// confirm the exact entry exists before readDex
try (ZipFile zf = new ZipFile(data)) {
    if (zf.findFirstEntry("classes.dex") == null) {
        throw new IllegalArgumentException("no classes.dex; use MultiDexFileReader.open for multi-dex");
    }
}

Try / catch

try {
    byte[] dex = ZipUtil.readDex(apkBytes);
} catch (IOException e) {
    LOG.warn("classes.dex missing, falling back to multi-dex reader");
    BaseDexFileReader r = MultiDexFileReader.open(apkBytes);
}

Prevention

When it happens

Trigger: Calling ZipUtil.readDex on a zip whose entries do not include exactly "classes.dex" — e.g. multi-dex APKs where the helper is expected to be called per-entry, resource-only zips, or APKs with dex entries renamed/encrypted.

Common situations: Using readDex on an APK that only has classes2.dex+ (rare) or renamed dex entries; packed APKs that hide dex files until runtime; confusing readDex with MultiDexFileReader.open which accepts any *.dex entries.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of pxb1988/dex2jar@b5bda4fb49 (2026-09-08). Data as JSON: /api/errors/1733b44e63145393. Report an issue: GitHub.

Appendix: source

Thrown at dex-reader/src/main/java/com/googlecode/d2j/reader/zip/ZipUtil.java:85

     * in the zip stream.
     * 
     * @param data
     * @return the content of classes.dex
     * @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)