MuntashirAkon/AppManager · error · IOException

{parserErrors} syntax errors during parsing and/or lexing.

Error message

{parserErrors} syntax errors during parsing and/or lexing.

What it means

DexUtils.toClassDef() first disassembles the target DEX to smali, then re-parses the smali text with the smaliParser (ANTLR-based). If the lexer or parser reports any syntax errors, the method throws this IOException so the failure surfaces as a plain message instead of half-built output. It means the smali input itself is malformed — the parser could not turn the text back into a syntax tree.

Source

Thrown at app/src/main/java/io/github/muntashirakon/AppManager/dex/DexUtils.java:124

            throws IOException, RecognitionException {
        try (StringReader sr = new StringReader(smaliContents)) {
            return toClassDef(sr, apiLevel);
        }
    }

    @NonNull
    public static ClassDef toClassDef(@NonNull Reader smaliReader, int apiLevel)
            throws IOException, RecognitionException {
        Opcodes opcodes = apiLevel < 0 ? Opcodes.getDefault() : Opcodes.forApi(apiLevel);
        smaliFlexLexer lexer = new smaliFlexLexer(smaliReader, opcodes.api);
        CommonTokenStream tokens = new CommonTokenStream(lexer);
        smaliParser parser = new smaliParser(tokens);
        parser.setVerboseErrors(false);
        parser.setAllowOdex(false);
        parser.setApiLevel(opcodes.api);
        smaliParser.smali_file_return result = parser.smali_file();
        if (parser.getNumberOfSyntaxErrors() > 0 || lexer.getNumberOfSyntaxErrors() > 0) {
            throw new IOException((parser.getNumberOfSyntaxErrors() + lexer.getNumberOfSyntaxErrors())
                    + " syntax errors during parsing and/or lexing.");
        }

        CommonTree t = result.getTree();
        CommonTreeNodeStream treeStream = new CommonTreeNodeStream(t);
        treeStream.setTokenStream(tokens);

        DexBuilder dexBuilder = new DexBuilder(opcodes);
        smaliTreeWalker dexGen = new smaliTreeWalker(treeStream);
        dexGen.setApiLevel(opcodes.api);
        dexGen.setVerboseErrors(false);
        dexGen.setDexBuilder(dexBuilder);
        ClassDef classDef = dexGen.smali_file();

        if (dexGen.getNumberOfSyntaxErrors() > 0) {
            throw new IOException(dexGen.getNumberOfSyntaxErrors() + " syntax errors during dex creation");
        }

View on GitHub (pinned to 0152f468fc)

Solutions

  1. Check the reported error count and enable verbose parser errors (parser.setVerboseErrors(true)) or run smali/baksmali standalone to get line-level diagnostics, then fix the smali syntax at the reported lines
  2. Match the API level: pass Opcodes for the correct API (or the APK's minSdk) so opcodes and directives are recognized
  3. Ensure the smali came from a compatible disassembly (baksmali) and wasn't truncated or hand-edited with invalid registers/directives
  4. If the input was odex, either enable odex support (setAllowOdex(true)) with deodex tools or de-odex the file before conversion

Example fix

// before
smaliParser parser = new smaliParser(tokens);
parser.setVerboseErrors(false);
parser.setApiLevel(opcodes.api);
smaliParser.smali_file_return result = parser.smali_file();
// after
smaliParser parser = new smaliParser(tokens);
parser.setVerboseErrors(true); // get line/column details on failure
parser.setApiLevel(Opcodes.forApi(29)); // match the API the smali targets
smaliParser.smali_file_return result = parser.smali_file();
Defensive patterns

Strategy: try-catch

Validate before calling

if (smali == null || smali.trim().isEmpty() || !smali.contains(".class ")) throw new IllegalArgumentException("Invalid smali input");

Type guard

boolean isPlausibleSmali(String s) { return s != null && s.contains(".class ") && s.contains(".super "); }

Try / catch

try { ClassDef def = DexUtils.toClassDef(smali, opcodes, dexBuilder); } catch (IOException e) { if (e.getMessage().contains("syntax errors")) { /* log smali source, fix syntax or report to user */ } else throw e; }

Prevention

When it happens

Trigger: Calling DexUtils.toClassDef() with smali text that contains invalid opcodes/registers/directives, smali produced by a disassembler at a mismatched API level (parser.setApiLevel(opcodes.api)), odex-only syntax when setAllowOdex(false), or corrupted round-tripped smali files.

Common situations: Reassembling DEX files after editing smali by hand; disassembling an app built for a newer API level than the Opcodes used for parsing; feeding odex/quickened bytecode-derived smali into a dex path; merge tools mangling smali syntax.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12). Data as JSON: /api/errors/d8cb8745f577f3e0. Report an issue: GitHub.