xref: /aosp_15_r20/frameworks/base/tools/aapt2/formats.md (revision d57664e9bc4670b3ecf6748a746a57c557b6bc9e)
1*d57664e9SAndroid Build Coastguard Worker# AAPT2 On-Disk Formats
2*d57664e9SAndroid Build Coastguard Worker- AAPT2 Container Format (extension `.apc`)
3*d57664e9SAndroid Build Coastguard Worker- AAPT2 Static Library Format (extension `.sapk`)
4*d57664e9SAndroid Build Coastguard Worker
5*d57664e9SAndroid Build Coastguard Worker## AAPT2 Container Format (extension `.apc`)
6*d57664e9SAndroid Build Coastguard WorkerThe APC format (AAPT2 Container Format) is generated by AAPT2 during the compile phase and
7*d57664e9SAndroid Build Coastguard Workerconsumed by the AAPT2 link phase. It is a simple container format for storing compiled PNGs,
8*d57664e9SAndroid Build Coastguard Workerbinary and protobuf XML, and intermediate protobuf resource tables. It also stores all associated
9*d57664e9SAndroid Build Coastguard Workermeta-data from the compile phase.
10*d57664e9SAndroid Build Coastguard Worker
11*d57664e9SAndroid Build Coastguard Worker### Format
12*d57664e9SAndroid Build Coastguard WorkerThe file starts with a simple header. All multi-byte fields are little-endian.
13*d57664e9SAndroid Build Coastguard Worker
14*d57664e9SAndroid Build Coastguard Worker| Size (in bytes) | Field         | Description                                          |
15*d57664e9SAndroid Build Coastguard Worker|:----------------|:--------------|:-----------------------------------------------------|
16*d57664e9SAndroid Build Coastguard Worker| `4`             | `magic`       | The magic bytes must equal `'AAPT'` or `0x54504141`. |
17*d57664e9SAndroid Build Coastguard Worker| `4`             | `version`     | The version of the container format.                 |
18*d57664e9SAndroid Build Coastguard Worker| `4`             | `entry_count` | The number of entries in this container.             |
19*d57664e9SAndroid Build Coastguard Worker
20*d57664e9SAndroid Build Coastguard WorkerThis is followed by `entry_count` of the following data structure. It must be aligned on a 32-bit
21*d57664e9SAndroid Build Coastguard Workerboundary, so if a previous entry ends unaligned, padding must be inserted.
22*d57664e9SAndroid Build Coastguard Worker
23*d57664e9SAndroid Build Coastguard Worker| Size (in bytes) | Field          | Description                                                                                               |
24*d57664e9SAndroid Build Coastguard Worker|:----------------|:---------------|:----------------------------------------------------------------------------------------------------------|
25*d57664e9SAndroid Build Coastguard Worker| `4`             | `entry_type`   | The type of the entry. This can be one of two types: `RES_TABLE (0x00000000)` or `RES_FILE (0x00000001)`. |
26*d57664e9SAndroid Build Coastguard Worker| `8`             | `entry_length` | The length of the data that follows.  Do not use if `entry_type` is `RES_FILE`; this value may be wrong.  |
27*d57664e9SAndroid Build Coastguard Worker| `entry_length`  | `data`         | The payload. The contents of this varies based on the `entry_type`.                                       |
28*d57664e9SAndroid Build Coastguard Worker
29*d57664e9SAndroid Build Coastguard WorkerIf the `entry_type` is equal to `RES_TABLE (0x00000000)`, the `data` field contains a serialized
30*d57664e9SAndroid Build Coastguard Worker[aapt.pb.ResourceTable](Resources.proto).
31*d57664e9SAndroid Build Coastguard Worker
32*d57664e9SAndroid Build Coastguard WorkerIf the `entry_type` is equal to `RES_FILE (0x00000001)`, the `data` field contains the following:
33*d57664e9SAndroid Build Coastguard Worker
34*d57664e9SAndroid Build Coastguard Worker
35*d57664e9SAndroid Build Coastguard Worker| Size (in bytes) | Field            | Description                                                                                               |
36*d57664e9SAndroid Build Coastguard Worker|:----------------|:-----------------|:----------------------------------------------------------------------------------------------------------|
37*d57664e9SAndroid Build Coastguard Worker| `4`             | `header_size`    | The size of the `header` field.                                                                           |
38*d57664e9SAndroid Build Coastguard Worker| `8`             | `data_size`      | The size of the `data` field.                                                                             |
39*d57664e9SAndroid Build Coastguard Worker| `header_size`   | `header`         | The serialized Protobuf message [aapt.pb.internal.CompiledFile](ResourcesInternal.proto).                 |
40*d57664e9SAndroid Build Coastguard Worker| `x`             | `header_padding` | Up to 3 bytes of zeros, if padding is necessary to align the `data` field on a 32-bit boundary.           |
41*d57664e9SAndroid Build Coastguard Worker| `data_size`     | `data`           | The payload, which is determined by the `type` field in the `aapt.pb.internal.CompiledFile`. This can be a PNG file, binary XML, or [aapt.pb.XmlNode](Resources.proto). |
42*d57664e9SAndroid Build Coastguard Worker| `y`             | `data_padding`   | Up to 3 bytes of zeros, if `data_size` is not a multiple of 4.                                            |
43*d57664e9SAndroid Build Coastguard Worker
44*d57664e9SAndroid Build Coastguard Worker## AAPT2 Static Library Format (extension `.sapk`)
45*d57664e9SAndroid Build Coastguard Worker
46