{"record":{"id":"d39a76b1b3b816ab","repo":"Tencent/tinker","slug":"expected-dex-in-jar-name-in-file","errorCode":null,"errorMessage":"Expected ${DEX_IN_JAR_NAME} in ${file}","messagePattern":"Expected (.+?) in (.+?)","errorType":"exception","errorClass":"DexException","httpStatus":null,"severity":"error","filePath":"third-party/aosp-dexutils/src/main/java/com/tencent/tinker/android/dex/Dex.java","lineNumber":148,"sourceCode":"        }\n\n        if (FileUtils.hasArchiveSuffix(file.getName())) {\n            ZipFile zipFile = null;\n            try {\n                zipFile = new ZipFile(file);\n                ZipEntry entry = zipFile.getEntry(DexFormat.DEX_IN_JAR_NAME);\n                if (entry != null) {\n                    InputStream inputStream = null;\n                    try {\n                        inputStream = zipFile.getInputStream(entry);\n                        loadFrom(inputStream, (int) entry.getSize());\n                    } finally {\n                        if (inputStream != null) {\n                            inputStream.close();\n                        }\n                    }\n                } else {\n                    throw new DexException(\"Expected \" + DexFormat.DEX_IN_JAR_NAME + \" in \" + file);\n                }\n            } finally {\n                if (zipFile != null) {\n                    try {\n                        zipFile.close();\n                    } catch (Exception e) {\n                        // ignored.\n                    }\n                }\n            }\n        } else if (file.getName().endsWith(\".dex\")) {\n            InputStream in = null;\n            try {\n                in = new BufferedInputStream(new FileInputStream(file));\n                loadFrom(in, (int) file.length());\n            } catch (Exception e) {\n                throw new DexException(e);\n            } finally {","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/Tencent/tinker/blob/1b7ea02c239840f563ea64fb5bd286eb98d4011e/third-party/aosp-dexutils/src/main/java/com/tencent/tinker/android/dex/Dex.java#L130-L166","documentation":"Thrown when Dex(File) opens a zip/jar/apk archive (name has an archive suffix) but the archive contains no entry named classes.dex (DexFormat.DEX_IN_JAR_NAME). The library only knows how to pull the single canonical classes.dex out of an archive; it does not scan for classes2.dex, arbitrary .dex entries, or nested archives.","triggerScenarios":"new Dex(new File(\"app.apk\")) where the apk's code lives in classes2.dex..classesN.dex (multidex) with no primary classes.dex; an apk with code stripped; passing a jar that is not a dex container.","commonSituations":"Multidexed release APKs, apks processed by tools that rename or remove classes.dex (e.g. some obfuscators or 8xx 'compact dex' outputs), or pointing the loader at a resource jar by mistake.","solutions":["Point Dex at the exact dex file: extract classes2.dex (or whichever) from the apk and pass the raw .dex file instead of the archive.","If you control packaging, ensure a primary classes.dex entry exists at the archive root.","Inspect the archive first (unzip -l / ZipFile.getEntry) to confirm which classesN.dex entries are present before constructing Dex."],"exampleFix":"// before\nDex dex = new Dex(new File(\"app.apk\")); // fails if only classes2.dex exists\n\n// after\ntry (ZipFile zip = new ZipFile(apk)) {\n    ZipEntry e = zip.getEntry(\"classes2.dex\");\n    try (InputStream in = zip.getInputStream(e)) {\n        Dex dex = new Dex(in, (int) e.getSize());\n    }\n}","handlingStrategy":"validation","validationCode":"try (ZipFile zip = new ZipFile(file)) {\n    if (zip.getEntry(\"classes.dex\") == null) {\n        // list available dex entries and pick explicitly, or fail with context\n        throw new IOException(\"no classes.dex in \" + file + \" (found: \" +\n            Collections.list(zip.entries()).stream().map(ZipEntry::getName)\n                .filter(n -> n.endsWith(\".dex\")).collect(Collectors.toList()) + \")\");\n    }\n}","typeGuard":null,"tryCatchPattern":"catch (DexException e) when message starts with \"Expected classes.dex\" -> report which classesN.dex entries exist and guide the caller to select one explicitly.","preventionTips":["For multidex apks always address a specific classesN.dex entry via ZipFile rather than passing the apk to Dex(File).","Treat archives as containers: enumerate dex entries yourself, then hand Dex the raw bytes."],"tags":["dex","zip","multidex","apk","tinker"],"backgroundTag":null,"analyzedSha":"1b7ea02c239840f563ea64fb5bd286eb98d4011e","analyzedAt":"2026-08-14T15:16:52.110Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}