{"record":{"id":"9553245605c428c2","repo":"pxb1988/dex2jar","slug":"can-not-find-classes-dex-in-zip-file","errorCode":null,"errorMessage":"Can not find classes.dex in zip file","messagePattern":"Can not find classes\\.dex in zip file","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"dex-reader/src/main/java/com/googlecode/d2j/reader/MultiDexFileReader.java","lineNumber":51,"sourceCode":"        if (data.length < 3) {\n            throw new IOException(\"File too small to be a dex/zip\");\n        }\n        if (\"dex\".equals(new String(data, 0, 3, StandardCharsets.ISO_8859_1))) {// dex\n            return new DexFileReader(data);\n        } else if (\"PK\".equals(new String(data, 0, 2, StandardCharsets.ISO_8859_1))) {// ZIP\n            TreeMap<String, DexFileReader> dexFileReaders = new TreeMap<>();\n            try (ZipFile zipFile = new ZipFile(data)) {\n                for (ZipEntry e : zipFile.entries()) {\n                    String entryName = e.getName();\n                    if (entryName.startsWith(\"classes\") && entryName.endsWith(\".dex\")) {\n                        if (!dexFileReaders.containsKey(entryName)) { // only the first one\n                            dexFileReaders.put(entryName, new DexFileReader(toByteArray(zipFile.getInputStream(e))));\n                        }\n                    }\n                }\n            }\n            if (dexFileReaders.size() == 0) {\n                throw new IOException(\"Can not find classes.dex in zip file\");\n            } else if (dexFileReaders.size() == 1) {\n                return dexFileReaders.firstEntry().getValue();\n            } else {\n                return new MultiDexFileReader(dexFileReaders.values());\n            }\n        }\n        throw new IOException(\"The source file is not a .dex or .zip file\");\n    }\n\n    void init() {\n        Set<String> classes = new HashSet<>();\n        for (DexFileReader reader : readers) {\n            List<String> classNames = reader.getClassNames();\n            for (int i = 0; i < classNames.size(); i++) {\n                String className = classNames.get(i);\n                if (classes.add(className)) {\n                    items.add(new Item(i, reader, className));\n                }","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/pxb1988/dex2jar/blob/b5bda4fb4935ae8b3869b422454ae3b3896c7bc1/dex-reader/src/main/java/com/googlecode/d2j/reader/MultiDexFileReader.java#L33-L69","documentation":"MultiDexFileReader.open(byte[]) throws IOException when the input is a valid ZIP (PK prefix) but no .dex entries were found inside it, so dexFileReaders ends up empty. The library expects APK/zip inputs to contain at least one classes*.dex entry.","triggerScenarios":"Calling MultiDexFileReader.open(bytes) on a zip/archive that contains no entries ending in .dex (case-sensitive filter), such as a plain zip of resources, an empty APK shell, or an APK where dex entries were stripped or renamed.","commonSituations":"Passing a renamed .zip or a resource bundle where an APK was expected; APKs processed by tools that removed or renamed classes.dex; encrypted/packed APKs where dex files are hidden until runtime unpacking.","solutions":["Confirm the input is a real APK containing classes.dex (unzip -l).","If entries use different names/casing, rename them to classes.dex / classes2.dex or unpack and rebuild the APK.","If the APK is protected/packed, dump the runtime dex files first (e.g. with a unpacker) and pass those dex bytes instead.","If you intended a raw dex, pass the .dex bytes directly instead of the zip."],"exampleFix":"// before\nBaseDexFileReader r = MultiDexFileReader.open(zipBytes);\n// after\nbyte[] dexBytes = ZipUtil.readDex(zipBytes); // throws its own clearer error\nBaseDexFileReader r = MultiDexFileReader.open(dexBytes);","handlingStrategy":"validation","validationCode":"// ensure zip contains at least one .dex before calling open\ntry (ZipFile zf = new ZipFile(data)) {\n    boolean hasDex = zf.getEntries().hasMoreElements() &&\n        java.util.Collections.list(zf.getEntries()).stream().anyMatch(e -> e.getName().endsWith(\".dex\"));\n    if (!hasDex) throw new IllegalArgumentException(\"zip has no classes*.dex entries\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    BaseDexFileReader r = MultiDexFileReader.open(bytes);\n} catch (IOException e) {\n    LOG.error(\"no dex inside zip: \" + e.getMessage());\n    // fall back to dumping runtime dex for packed APKs\n}","preventionTips":["Confirm APK contents with unzip -l before analysis","Use MultiDexFileReader.open (all *.dex) rather than expecting exactly classes.dex","Unpack protected APKs at runtime to recover hidden dex files"],"tags":["dex","android","zip","apk"],"backgroundTag":"resource-not-found","analyzedSha":"b5bda4fb4935ae8b3869b422454ae3b3896c7bc1","analyzedAt":"2026-09-08T00:44:01.258Z","contentChangedAt":"2026-09-08T00:44:01.258Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}