{"record":{"id":"ea659d7aa5329253","repo":"Tencent/tinker","slug":"old-dex-version-mismatch-expetced","errorCode":null,"errorMessage":"old dex version mismatch! expetced: ","messagePattern":"old dex version mismatch! expetced: ","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"critical","filePath":"tinker-commons/src/main/java/com/tencent/tinker/commons/dexpatcher/DexPatchApplier.java","lineNumber":125,"sourceCode":"            DexPatchFile patchFileIn\n    ) {\n        this.oldDex = oldDexIn;\n        this.patchFile = patchFileIn;\n        this.patchedDex = new Dex(patchFileIn.getPatchedDexSize());\n        this.oldToPatchedIndexMap = new SparseIndexMap();\n    }\n\n    public void executeAndSaveTo(OutputStream out) throws IOException {\n        // Before executing, we should check if this patch can be applied to\n        // old dex we passed in.\n        if (this.patchFile == null) {\n            throw new IllegalArgumentException(\"patch file is null.\");\n        }\n        if (this.patchFile.getVersion() > DexPatchFile.VERSION_02) {\n            final int oldDexAPI = this.oldDex.getTableOfContents().api;\n            final int expectedOldDexAPI = this.patchFile.getOldDexAPI();\n            if (oldDexAPI != expectedOldDexAPI) {\n                throw new IOException(\"old dex version mismatch! expetced: \"\n                        + expectedOldDexAPI + \", actual: \" + oldDexAPI);\n            }\n        }\n        byte[] oldDexSign = this.oldDex.computeSignature(false);\n        if (oldDexSign == null) {\n            throw new IOException(\"failed to compute old dex's signature.\");\n        }\n        byte[] oldDexSignInPatchFile = this.patchFile.getOldDexSignature();\n        if (CompareUtils.uArrCompare(oldDexSign, oldDexSignInPatchFile) != 0) {\n            throw new IOException(\n                    String.format(\n                            \"old dex signature mismatch! expected: %s, actual: %s\",\n                            Arrays.toString(oldDexSign),\n                            Arrays.toString(oldDexSignInPatchFile)\n                    )\n            );\n        }\n","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/Tencent/tinker/blob/1b7ea02c239840f563ea64fb5bd286eb98d4011e/tinker-commons/src/main/java/com/tencent/tinker/commons/dexpatcher/DexPatchApplier.java#L107-L143","documentation":"IOException from DexPatchApplier.executeAndSaveTo: for patch format v03+, the patch file records the dex API level of the old dex it was generated against, and the runtime old dex's TableOfContents.api differs. The patch cannot be applied because section layout differs between the two dex versions.","triggerScenarios":"Applying a v03+ dex patch to an old dex whose api field (dex version, e.g., 035 vs 038) differs from getOldDexAPI() recorded at diff time.","commonSituations":"Base apk rebuilt with a different AGP/compileSdk (changing dex version) after the patch was made; applying a patch to the wrong base version; distributing patches built against a debug build to a release build.","solutions":["Regenerate the patch against the exact base apk currently distributed","Keep build toolchain versions identical between the patch-generation build and the released base package","Enforce base-version checks in your patch distribution service before delivery"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if (patchFile.getVersion() > DexPatchFile.VERSION_02\n        && oldDex.getTableOfContents().api != patchFile.getOldDexAPI()) {\n    throw new IOException(\"refusing to apply: dex api mismatch, regenerate patch for this base\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    applier.executeAndSaveTo(out);\n} catch (IOException e) {\n    if (String.valueOf(e.getMessage()).startsWith(\"old dex version mismatch\")) {\n        // signal server to rebuild patch against installed base version\n    } else { throw e; }\n}","preventionTips":["Freeze AGP/compileSdk between base release and patch builds","Distribute patches keyed by base apk version and verify server-side"],"tags":["dexpatcher","version-mismatch","dex-api","patch-apply"],"backgroundTag":null,"analyzedSha":"1b7ea02c239840f563ea64fb5bd286eb98d4011e","analyzedAt":"2026-08-14T15:16:52.110Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}