shwenzhang/AndResGuard · error · brut.androlib.AndrolibException
Invalid chunk type: expected=
Error message
Invalid chunk type: expected=%d, got=%d
What it means
In the write/encode pass, writeNextChunkCheck reads the next chunk header, writes it through with a size adjustment (diffSize), and asserts the chunk type matches what the encoder expects next. A mismatch means the source arsc structure deviates from the decode order, so the re-serialized table would be invalid and the tool aborts.
Solutions
- Run AndResGuard on the original aapt-built APK only, never on already-processed output
- Rebuild resources.arsc with the official Android build tools
- Upgrade AndResGuard to the latest version
- Diff the arsc chunk layout with aapt dump resources to identify the unexpected chunk
Example fix
// before apply plugin: 'AndResGuard' // reprocessing a previously guarded apk // after: feed the plugin the original unsigned release apk from the build pipeline
Defensive patterns
Strategy: try-catch
Validate before calling
if (!originalApkChecksumMatches(buildOutput)) throw new IllegalStateException("Input must be the original aapt-built APK"); Try / catch
try {
encodeArsc(in, out);
} catch (AndrolibException e) {
if (e.getMessage().startsWith("Invalid chunk type")) {
logger.error("Write pass hit unexpected chunk; input arsc is non-standard");
fallbackToNonObfuscatedBuild();
} else throw e;
} Prevention
- Feed the plugin only original build artifacts (checksum them in CI)
- Do not chain multiple resource-processing tools
- Rebuild arsc with aapt/aapt2 if the error persists
- Keep AndResGuard updated for new arsc layouts
When it happens
Trigger: During re-encoding, Header.readAndWriteHeader returns a header whose type != expectedType — the write-pass chunk sequence diverges from the expected table/package/typespec/config ordering, typically due to a modified or non-standard resources.arsc.
Common situations: Double-obfuscated APKs, arsc rewritten by repackers, arsc built by tools emitting chunks in a different order, or corruption in the input APK.
Related errors
- Invalid chunk type: expected=0x%08x, got=0x%08x
- readAndWriteHeader size < 0: size=
- Invalid chunk type: expected=0x%08x, got=0x%08x
- Config size < 28
- Could not decode arsc file
AI-assisted analysis of shwenzhang/AndResGuard@e4df245d82 (2026-09-12).
Data as JSON: /api/errors/9e86cafa83b7d1f9.
Report an issue: GitHub.
Appendix: source
Thrown at AndResGuard-core/src/main/java/com/tencent/mm/androlib/res/decoder/ARSCDecoder.java:993
mHeader.type
));
}
}
private void nextChunkCheckType(int expectedType) throws IOException, AndrolibException {
nextChunk();
checkChunkType(expectedType);
}
private Header writeNextChunk(int diffSize) throws IOException, AndrolibException {
mHeader = Header.readAndWriteHeader(mIn, mOut, diffSize);
return mHeader;
}
private Header writeNextChunkCheck(int expectedType, int diffSize) throws IOException, AndrolibException {
mHeader = Header.readAndWriteHeader(mIn, mOut, diffSize);
if (mHeader.type != expectedType) {
throw new AndrolibException(String.format("Invalid chunk type: expected=%d, got=%d", expectedType, mHeader.type));
}
return mHeader;
}
/**
* 为了加速,不需要处理string,id,array,这几个是肯定不是的
*/
private boolean isToResguardFile(String name) {
return (!name.equals("string") && !name.equals("id") && !name.equals("array"));
}
public static class Header {
public final static short TYPE_NONE = -1, TYPE_TABLE = 0x0002, TYPE_PACKAGE = 0x0200, TYPE_TYPE = 0x0201,
TYPE_SPEC_TYPE = 0x0202, TYPE_LIBRARY = 0x0203;
public final short type;
public final int chunkSize;
View on GitHub (pinned to e4df245d82)