Adam Lesinski | 0045116 | 2017-10-03 07:44:08 -0700 | [diff] [blame] | 1 | # AAPT2 On-Disk Formats |
| 2 | - AAPT2 Container Format (extension `.apc`) |
| 3 | - AAPT2 Static Library Format (extension `.sapk`) |
| 4 | |
| 5 | ## AAPT2 Container Format (extension `.apc`) |
| 6 | The APC format (AAPT2 Container Format) is generated by AAPT2 during the compile phase and |
| 7 | consumed by the AAPT2 link phase. It is a simple container format for storing compiled PNGs, |
| 8 | binary and protobuf XML, and intermediate protobuf resource tables. It also stores all associated |
| 9 | meta-data from the compile phase. |
| 10 | |
| 11 | ### Format |
| 12 | The file starts with a simple header. All multi-byte fields are little-endian. |
| 13 | |
| 14 | | Size (in bytes) | Field | Description | |
| 15 | |:----------------|:--------------|:-----------------------------------------------------| |
| 16 | | `4` | `magic` | The magic bytes must equal `'AAPT'` or `0x54504141`. | |
| 17 | | `4` | `version` | The version of the container format. | |
| 18 | | `4` | `entry_count` | The number of entries in this container. | |
| 19 | |
| 20 | This is followed by `entry_count` of the following data structure. It must be aligned on a 32-bit |
| 21 | boundary, so if a previous entry ends unaligned, padding must be inserted. |
| 22 | |
| 23 | | Size (in bytes) | Field | Description | |
| 24 | |:----------------|:---------------|:----------------------------------------------------------------------------------------------------------| |
| 25 | | `4` | `entry_type` | The type of the entry. This can be one of two types: `RES_TABLE (0x00000000)` or `RES_FILE (0x00000001)`. | |
Donald Chai | 6f61387 | 2019-10-19 13:38:52 -0700 | [diff] [blame] | 26 | | `8` | `entry_length` | The length of the data that follows. Do not use if `entry_type` is `RES_FILE`; this value may be wrong. | |
Adam Lesinski | 0045116 | 2017-10-03 07:44:08 -0700 | [diff] [blame] | 27 | | `entry_length` | `data` | The payload. The contents of this varies based on the `entry_type`. | |
| 28 | |
| 29 | If the `entry_type` is equal to `RES_TABLE (0x00000000)`, the `data` field contains a serialized |
| 30 | [aapt.pb.ResourceTable](Resources.proto). |
| 31 | |
| 32 | If the `entry_type` is equal to `RES_FILE (0x00000001)`, the `data` field contains the following: |
| 33 | |
| 34 | |
Donald Chai | 6f61387 | 2019-10-19 13:38:52 -0700 | [diff] [blame] | 35 | | Size (in bytes) | Field | Description | |
| 36 | |:----------------|:-----------------|:----------------------------------------------------------------------------------------------------------| |
| 37 | | `4` | `header_size` | The size of the `header` field. | |
| 38 | | `8` | `data_size` | The size of the `data` field. | |
| 39 | | `header_size` | `header` | The serialized Protobuf message [aapt.pb.internal.CompiledFile](ResourcesInternal.proto). | |
| 40 | | `x` | `header_padding` | Up to 3 bytes of zeros, if padding is necessary to align the `data` field on a 32-bit boundary. | |
| 41 | | `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 | | `y` | `data_padding` | Up to 3 bytes of zeros, if `data_size` is not a multiple of 4. | |
Adam Lesinski | 0045116 | 2017-10-03 07:44:08 -0700 | [diff] [blame] | 43 | |
| 44 | ## AAPT2 Static Library Format (extension `.sapk`) |
| 45 | |