shwenzhang/AndResGuard · error · AndrolibException

Invalid chunk type: expected=0x%08x, got=0x%08x

Error message

Invalid chunk type: expected=0x%08x, got=0x%08x

What it means

RawARSCDecoder.checkChunkType validates that the chunk header read by nextChunk() matches the expected chunk type constant while walking the table, package, library, type-spec and config sections of resources.arsc. A mismatch indicates the arsc's structural layout differs from the expected format — corruption, an unsupported format version, or a misaligned read.

Solutions

  1. Upgrade AndResGuard to a version supporting the arsc features in your APK (e.g. shared library chunks)
  2. Rebuild the APK with the official Android build tools
  3. Verify the input APK integrity (aapt dump resources) and re-obtain a clean copy
  4. Disable other resource-processing plugins that may rewrite resources.arsc before AndResGuard runs

Example fix

// before: old plugin choking on aapt2 library chunks
classpath('com.tencent.mm:AndResGuard-gradle-plugin:1.1.x')
// after
classpath('com.tencent.mm:AndResGuard-gradle-plugin:1.2.21')
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-check: ensure aapt can fully walk the arsc
// aapt dump resources app.apk > /dev/null || exit 1

Try / catch

try {
  RawARSCDecoder.decode(arscStream);
} catch (AndrolibException e) {
  if (e.getMessage().startsWith("Invalid chunk type")) {
    logger.warn("Unexpected arsc chunk — upgrading AndResGuard or rebuilding the apk");
    fallbackToUnobfuscatedBuild();
  } else throw e;
}

Prevention

When it happens

Trigger: Called from readTablePackage, readLibraryType, readSingleTableTypeSpec, readConfig or nextChunkCheckType when mHeader.type != expectedType — e.g. an unknown/missing library chunk, a package chunk where a type-spec was expected, or garbage after a truncated section.

Common situations: APKs with shared-library chunks (library type) handled by older AndResGuard, arsc produced by new aapt2 versions, repacked/corrupted APKs, or non-standard resource tools.

Related errors


AI-assisted analysis of shwenzhang/AndResGuard@e4df245d82 (2026-09-12). Data as JSON: /api/errors/307915d51b0505ab. Report an issue: GitHub.

Appendix: source

Thrown at AndResGuard-core/src/main/java/com/tencent/mm/androlib/res/decoder/RawARSCDecoder.java:354

    while (length-- != 0) {
      short ch = mIn.readByte();
      if (ch == 0) {
        break;
      }
      string.append((char) ch);
    }
    mIn.skipBytes(length);

    return string.toString();
  }

  private Header nextChunk() throws IOException {
    return mHeader = Header.read(mIn, mCountIn);
  }

  private void checkChunkType(int expectedType) throws AndrolibException {
    if (mHeader.type != expectedType) {
      throw new AndrolibException(String.format("Invalid chunk type: expected=0x%08x, got=0x%08x",
          expectedType,
          mHeader.type
      ));
    }
  }

  private void nextChunkCheckType(int expectedType) throws IOException, AndrolibException {
    nextChunk();
    checkChunkType(expectedType);
  }

  private void putTypeSpecNameStrings(int type, String name) {
    Set<String> names = mExistTypeNames.get(type);
    if (names == null) {
      names = new HashSet<>();
    }
    names.add(name);
    mExistTypeNames.put(type, names);

View on GitHub (pinned to e4df245d82)