iBotPeaches/Apktool · error · XmlPullParserException
Could not initialize parser.
Error message
Could not initialize parser.
What it means
Wrapper exception: setInput() converts any IOException raised during initial AXML chunk reading (empty input [30], wrong first chunk [31], stream failure) into a standard XmlPullParserException with this message, resetting parser state. The real cause is attached as the chained exception.
Source
Thrown at brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/BinaryXmlResourceParser.java:124
public void setInput(InputStream inputStream, String inputEncoding) throws XmlPullParserException {
if (inputEncoding != null) {
throw new XmlPullParserException(NOT_SUPPORTED);
}
reset();
mIn = new BinaryDataInputStream(new BufferedInputStream(inputStream));
mParser = new ResChunkPullParser(mIn);
try {
if (!nextChunk()) {
throw new IOException("Input file is empty.");
}
if (mParser.chunkType() != ResChunkHeader.RES_XML_TYPE) {
throw new IOException("Unexpected chunk: " + mParser.chunkName() + " (expected: RES_XML_TYPE)");
}
} catch (IOException ex) {
mIn = null;
mParser = null;
throw new XmlPullParserException("Could not initialize parser.", this, ex);
}
mParser = new ResChunkPullParser(mIn, mParser.dataSize());
}
@Override
public String getInputEncoding() {
return null;
}
@Override
public void defineEntityReplacementText(String entityName, String replacementText) throws XmlPullParserException {
throw new XmlPullParserException(NOT_SUPPORTED);
}
@Override
public int getNamespaceCount(int depth) {
return mNamespaces.getCount(depth);View on GitHub (pinned to 79b63384d7)
Solutions
- Unwrap the cause: `ex.getCause()` reveals 'Input file is empty.' or 'Unexpected chunk: ...' — follow the fix for [30] or [31].
- Validate the AXML magic bytes (0x0003) and non-zero size before calling setInput.
- Ensure the InputStream is open and positioned at 0 (not reused after a prior read).
- Re-obtain the APK/file if the cause indicates truncation.
Example fix
try {
parser.setInput(in, null);
} catch (XmlPullParserException e) {
Throwable root = e.getCause();
log.error("AXML init failed: {}", root != null ? root.getMessage() : e.getMessage());
throw e;
} Defensive patterns
Strategy: try-catch
Validate before calling
if (inputStream == null) throw new IllegalArgumentException("null stream");
if (file != null && file.length() < 8) throw new IllegalArgumentException("AXML too small"); Try / catch
try {
parser.setInput(in, null);
} catch (XmlPullParserException e) {
Throwable cause = e.getCause();
if (cause instanceof IOException) {
// empty input, wrong chunk type, or stream failure — see [30]/[31]
}
} Prevention
- Always inspect the chained cause of XmlPullParserException from setInput.
- Pre-validate magic and size before initializing the parser.
When it happens
Trigger: Any of the conditions in [30]/[31], or a low-level read failure on the InputStream during initialization — e.g. stream already closed, network stream dropped.
Common situations: Callers using the XmlPullParser API generically see this instead of the raw IOException; typical roots are empty/corrupt AXML files or non-AXML input routed to the binary parser.
Related errors
- Input file is empty.
- Unexpected chunk:
- Parser must be on START_TAG to read next text.
- Parser must be on TEXT or END_TAG to read text.
- Event TEXT must be immediately followed by END_TAG.
AI-assisted analysis of iBotPeaches/Apktool@79b63384d7 (2026-08-14).
Data as JSON: /api/errors/f1de96f75736a43e.
Report an issue: GitHub.