Search code examples
androidaapt2

AAPT2 warning about "Unknown chunk type"


I'm building an Android app targeting Android API 33 (Android 13). When I build the app on the command line using gradlew, I see the following warning:

aapt2 W 09-02 02:57:09  6715  6715 LoadedArsc.cpp:682] Unknown chunk type '200'.

What on earth does this mean, and should I expect side effects?


Solution

  • Let's take a look at the LoadedAsrc.cpp file mentioned, used in relation to resources.arsc. Your warning mentions line 682, and if we look a few lines before that, we can see your warning on line 677.

    This warning seems to happen if whilst looking through the "overlayable policy chunks", we find a overlayable_child_chunk.type() that does not equal RES_TABLE_OVERLAYABLE_POLICY_TYPE.

    By looking at the switch and case statements, we can see that child chunks of a RES_TABLE_TYPE_SPEC_TYPE chunk should be of type RES_TABLE_OVERLAYABLE_POLICY_TYPE, defined in this older copy of the code as 0x0205 (517?), not the 200 shown in your error. When a child chunk is the incorrect type, we go to default, throwing the warning seen.

    This warning is being called inside LoadedPackage::Load, where we are trying to populate type_builder_map using loaded_package (see line 748). So, now we know that we're seeing this warning because a child chunk type is set incorrectly whilst trying to do... something around building up a map of types. This is summarised as:

      // A map of TypeSpec builders, each associated with an type index.
      // We use these to accumulate the set of Types available for a TypeSpec, and later build a single,
      // contiguous block of memory that holds all the Types together with the TypeSpec.
    

    At this point, there's not much value in diving deeper in my opinion. The main takeaway is:

    This warning is generated deep inside the compiler, and doesn't matter so long as everything works. It is caused by a type mismatch whilst building up a mapping for your app's resources.arsc file.

    I strongly suspect it's just a compiler bug, and doubt you can fix it yourself besides waiting for a later compiler version (updating target API) where this will hopefully be fixed.

    However, if you do want to dive deeper, I found this Chinese analysis (needs translating, search in page for LoadedPackage::Load!) extremely detailed. It contains a high level description of the load function, the file itself, and what the chunk loading actually means.

    It includes this helpful diagram, showing how all the parts interact, and specifically our _TYPE parsing:

    apk assets parsing