pxb1988/dex2jar · error · RuntimeException

Failed to add HEX_CLASS_LOCATION.decode_*

Error message

Failed to add HEX_CLASS_LOCATION.decode_*

What it means

Dex2Asm injects the synthetic HEX_CLASS_LOCATION.decode_* helper method (a hex-decoding bootstrap used to embed large byte arrays in generated classes) into output classes via ASM. If any Throwable escapes that visit/injection process, it is rethrown wrapped as 'Failed to add HEX_CLASS_LOCATION.decode_*'. The root cause is in the chained throwable, not the message itself.

Solutions

  1. Read the chained cause (t) to find the real failure — most often MethodTooLargeException from overly large embedded data
  2. Reduce the size of the embedded data/method being converted, or split it into multiple classes/methods
  3. Upgrade dex-translator and its ASM dependency to compatible versions
  4. Increase heap only if the cause is OutOfMemoryError

Example fix

// diagnosing
try { dex2asm.convert(...); } catch (RuntimeException e) {
    e.getCause().printStackTrace(); // real reason, e.g. MethodTooLargeException
}
// before: one giant data blob in a single method
// after: split embedded arrays across multiple classes/methods
Defensive patterns

Strategy: try-catch

Try / catch

try {
    dex2asm.convert(...);
} catch (RuntimeException e) {
    Throwable cause = e.getCause();
    if (cause instanceof MethodTooLargeException) {
        // split the offending data/method and retry
    } else if (cause instanceof OutOfMemoryError || cause instanceof ClassFormatError) {
        log.error("class generation failed", cause);
    } else throw e;
}

Prevention

When it happens

Trigger: Running the code path that augments generated classes with the hex-decode helper — e.g. ASM errors (MethodTooLargeException, ClassFormatError), ASM version incompatibilities, or memory issues while writing the enlarged class during jar2dex conversion.

Common situations: Converting very large methods/data arrays where the synthesized decode_* method exceeds the 64KB method limit (MethodTooLargeException), or class format/ASM version mismatches in dex-to-jar translation pipelines.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


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

Appendix: source

Thrown at dex-translator/src/main/java/com/googlecode/d2j/dex/Dex2Asm.java:584

                                        hexDecodeMethodNameBase + "$" + name, desc, signature, exceptions)) {
                            @Override
                            public void visitMethodInsn(int opcode, String owner, String name, String descriptor,
                                                        boolean isInterface) {
                                if (owner.equals(HEX_CLASS_LOCATION)) {
                                    super.visitMethodInsn(opcode, className, hexDecodeMethodNameBase + "$" + name,
                                            descriptor, isInterface);
                                } else {
                                    super.visitMethodInsn(opcode, owner, name, descriptor, isInterface);
                                }
                            }
                        };
                    } else {
                        return super.visitMethod(access, name, desc, signature, exceptions);
                    }
                }
            }, ClassReader.EXPAND_FRAMES);
        } catch (Throwable t) {
            throw new RuntimeException("Failed to add " + HEX_CLASS_LOCATION + ".decode_*", t);
        }
    }
    public void convertCode(DexMethodNode methodNode, MethodVisitor mv, ClzCtx clzCtx) {
        IrMethod irMethod = dex2ir(methodNode);
        optimize(irMethod);
        ir2j(irMethod, mv, clzCtx);
    }

    public void convertDex(DexFileNode fileNode, ClassVisitorFactory cvf) {
        if (fileNode.clzs != null) {
            Map<String, Clz> classes = collectClzInfo(fileNode);
            for (DexClassNode classNode : fileNode.clzs) {
                convertClass(fileNode, classNode, cvf, classes);
            }
        }
    }

    public void convertField(DexClassNode classNode, DexFieldNode fieldNode, ClassVisitor cv) {

View on GitHub (pinned to b5bda4fb49)