Tencent/matrix · error · AndrolibException

Could not decode XML,<var7.getMessage()>

Error message

Could not decode XML,<var7.getMessage()>

What it means

XmlPullResourceRefDecoder.decode() parses Android binary/resource XML with an XmlPullParser; on XmlPullParserException it wraps the failure in AndrolibException("Could not decode XML,..."). Called from decodeResResource, decodeResValues and decodeResourcesRef when decoding the compiled resource XML inside the APK.

Solutions

  1. Inspect var7.getMessage() in the AndrolibException cause for the parse position and token type.
  2. Analyze an APK built without resource obfuscation, or supply the matching resguard mapping so names decode correctly.
  3. Verify the extracted XML files are complete (re-unzip to a clean directory) and match the target SDK's binary XML format.

Example fix

// before
// analyzing an AndResGuard-processed APK with default decoder config
// after
config.setResMappingFilePath("build/resguard/resguard-mapping.txt"); // enable proper decoding
Defensive patterns

Strategy: try-catch

Validate before calling

// ensure the APK entry to decode exists and is non-empty
ZipEntry entry = zipFile.getEntry("AndroidManifest.xml");
if (entry == null || entry.getSize() == 0) {
    throw new IllegalStateException("Required XML entry missing or empty");
}

Try / catch

try {
    decoder.decode(inputStream);
} catch (AndrolibException e) {
    if (e.getMessage().startsWith("Could not decode XML")) {
        logger.error("Binary XML decode failed (possibly obfuscated resources): " + e.getMessage(), e.getCause());
    } else throw e;
}

Prevention

When it happens

Trigger: Feeding a malformed, non-binary, or truncated XML stream (e.g. plain-text XML where compiled binary XML is expected, or AAPT2-obfuscated resources) into decode via UnzipTask's resource analysis.

Common situations: Analyzing APKs built with resource obfuscation/packers (e.g. AndResGuard variants) that alter binary XML structure; truncated extraction due to disk issues; hand-modified resource files.

Related errors


AI-assisted analysis of Tencent/matrix@3b8293bd65 (2026-09-08). Data as JSON: /api/errors/6a5849b03fb02b1e. Report an issue: GitHub.

Appendix: source

Thrown at matrix/matrix-android/matrix-apk-canary/src/main/java/com/tencent/matrix/apk/model/task/util/XmlPullResourceRefDecoder.java:69

            mParser.setInput(inputStream, null);
            int token = mParser.next();
            while (token != XmlPullParser.END_DOCUMENT) {
                switch (token) {
                    case XmlPullParser.START_TAG:
                        handleElement();
                        break;
                    case XmlPullParser.TEXT:
                        handleContent();
                        break;
                    default:
                        break;
                }
                token = mParser.next();
            }
//            Log.i(TAG, "find resource references: %s", resourceRefSet);
            inputStream.close();
        } catch (XmlPullParserException var7) {
            throw new AndrolibException("Could not decode XML," + var7.getMessage(), var7);
        } catch (IOException e) {
            throw new AndrolibException("Parse xml error," + e.getMessage(), e);
        }
    }

    private void handleElement() {
        String tagName = mParser.getName();
        int pointIndex = tagName.lastIndexOf('.');
        if (pointIndex >= 0) {
            tagName = tagName.substring(pointIndex + 1);
        }
        if (!Util.isNullOrNil(tagName)) {
            for (int i = 0; i < mParser.getAttributeCount(); i++) {
                String value = mParser.getAttributeValue(i);
                //Log.d(TAG, "attribute %s, %s", name, value);
                if (!Util.isNullOrNil(value)) {
                    if (value.startsWith("@")) {
                        int index = value.indexOf('/');

View on GitHub (pinned to 3b8293bd65)