pxb1988/dex2jar · error · DexException

Failed to convert code for

Error message

Failed to convert code for %s

What it means

ExDex2Asm.convertCode wraps Dex2Asm.convertCode (dex IR -> JVM bytecode) and converts any Exception into a DexException naming the failing method via 'Failed to convert code for %s'. If an exceptionHandler is configured, it instead clears the method body and lets the handler decide (skip/stub the method) so translation of the rest of the class can continue.

Solutions

  1. Read the chained cause and the %s method name to identify the specific unsupported construct
  2. Install/configure an exceptionHandler (ExceptionHandler) on ExDex2Asm to stub or skip untranslatable methods instead of aborting the whole conversion
  3. Upgrade dex-translator to a newer build that handles the failing opcode/pattern
  4. Try disabling aggressive optimizations on the input dex (rebuild without optimization) before conversion

Example fix

// before: aborts whole conversion on one bad method
ExDex2Asm cv = new ExDex2Asm();
// after: register a handler so failing methods are skipped
ExDex2Asm cv = new ExDex2Asm();
cv.exceptionHandler = (method, methodNode, mn, ex) -> {
    log.warn("skipping " + method, ex); // leave mn empty
};
Defensive patterns

Strategy: try-catch

Try / catch

try {
    exDex2asm.convert(...);
} catch (DexException e) {
    log.error("method failed: " + e.getMessage(), e.getCause());
    // either skip the class or install exceptionHandler and re-run
}

Prevention

When it happens

Trigger: Any failure while translating a dex method's bytecode to JVM bytecode: unsupported opcodes/ODATA patterns, IR optimization crashes (e.g. NullPointerException in ir2j), stack-frame generation failures, or methods using exotic dex features the converter doesn't handle.

Common situations: Converting obfuscated or heavily optimized dex files (proguard/R8 output), multidex apps with uncommon method constructs, or older/newer dex format features than the translator supports.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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

Appendix: source

Thrown at dex-translator/src/main/java/com/googlecode/d2j/dex/ExDex2Asm.java:43

import com.googlecode.d2j.node.DexMethodNode;

public class ExDex2Asm extends Dex2Asm {
    final protected DexExceptionHandler exceptionHandler;

    public ExDex2Asm(DexExceptionHandler exceptionHandler) {
        this.exceptionHandler = exceptionHandler;
    }

    @Override
    public void convertCode(DexMethodNode methodNode, MethodVisitor mv, ClzCtx clzCtx) {
        MethodVisitor mw = AsmBridge.searchMethodWriter(mv);
        MethodNode mn = new MethodNode(Opcodes.ASM9, methodNode.access, methodNode.method.getName(),
                methodNode.method.getDesc(), null, null);
        try {
            super.convertCode(methodNode, mn, clzCtx);
        } catch (Exception ex) {
            if (exceptionHandler == null) {
                throw new DexException(ex, "Failed to convert code for %s", methodNode.method);
            } else {
                mn.instructions.clear();
                mn.tryCatchBlocks.clear();
                exceptionHandler.handleMethodTranslateException(methodNode.method, methodNode, mn, ex);
            }
        }
        // code convert ok, copy to MethodWriter and check for Size
        try {
            mn.accept(mv);
        } catch (Exception e) {
            System.out.println("Cannot convert " + clzCtx.classDescriptor);
            if (exceptionHandler != null)
                exceptionHandler.handleMethodTranslateException(methodNode.method, methodNode, mn, e);
        }
        if (mw != null) {
            try {
                AsmBridge.sizeOfMethodWriter(mw);
            } catch (Exception ex) {

View on GitHub (pinned to b5bda4fb49)