iBotPeaches/Apktool · error · XmlPullParserException

Event TEXT must be immediately followed by END_TAG.

Error message

Event TEXT must be immediately followed by END_TAG.

What it means

Tail check of nextText(): after reading the TEXT event, the immediately following event must be the matching END_TAG. A START_TAG (nested markup after text) or END_DOCUMENT at that position violates well-formed single-text-element semantics and throws.

Source

Thrown at brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/BinaryXmlResourceParser.java:561

        }
    }

    @Override
    public String nextText() throws XmlPullParserException, IOException {
        if (mEventType != START_TAG) {
            throw new XmlPullParserException("Parser must be on START_TAG to read next text.", this, null);
        }
        int eventType = next();
        if (eventType == END_TAG) {
            return "";
        }
        if (eventType != TEXT) {
            throw new XmlPullParserException("Parser must be on TEXT or END_TAG to read text.", this, null);
        }
        String result = getText();
        eventType = next();
        if (eventType != END_TAG) {
            throw new XmlPullParserException("Event TEXT must be immediately followed by END_TAG.", this, null);
        }
        return result;
    }

    @Override
    public int nextTag() throws XmlPullParserException, IOException {
        int eventType = next();
        if (eventType == TEXT && isWhitespace()) {
            eventType = next();
        }
        if (eventType != START_TAG && eventType != END_TAG) {
            throw new XmlPullParserException("Expected start or end tag.", this, null);
        }
        return eventType;
    }

    // Utility methods

View on GitHub (pinned to 79b63384d7)

Solutions

  1. Use manual event iteration (next() loop) for elements that can contain markup after text.
  2. Re-extract the AXML if truncation is suspected; a valid AXML always closes its tags.
  3. Validate the file with apktool's full decode — if full decode succeeds, fix the client traversal instead.
  4. Check file size and trailing bytes (0x0101 END_DOCUMENT chunk) when corruption is suspected.
Defensive patterns

Strategy: try-catch

Try / catch

try {
    String text = parser.nextText();
} catch (XmlPullParserException e) {
    if (e.getMessage().contains("immediately followed by END_TAG")) {
        // markup after text or truncated document — iterate manually / re-extract file
    }
}

Prevention

When it happens

Trigger: nextText() on an element like `<item>text<sub/></item>` where another tag follows the text node, or truncated AXML where the document ends right after a text node.

Common situations: Styled string resources compiled to AXML with inline tags; corrupt/truncated binary XML from bad extractions; packers mangling event sequences.

Related errors


AI-assisted analysis of iBotPeaches/Apktool@79b63384d7 (2026-08-14). Data as JSON: /api/errors/0aa82de81fac7ff1. Report an issue: GitHub.