Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

fix(android): ConfigValue.value is field 2, and field 3 is reserved

yhh4371d8fa6a2d
diff --git a/build-tools/tests/verify-aab.py b/build-tools/tests/verify-aab.py
index 61632d889..f34c2ded8 100644
--- a/build-tools/tests/verify-aab.py
+++ b/build-tools/tests/verify-aab.py
@@ -193,16 +193,22 @@ def resource_files(table):
Walked by field number, which is the half of this format that cannot be
inferred from the bytes: ResourceTable.package(2) -> Package.type(3) ->
- Type.entry(3) -> Entry.config_value(6) -> ConfigValue.value(3) ->
+ Type.entry(3) -> Entry.config_value(6) -> ConfigValue.value(2) ->
Value.item(4) -> Item.file(5) -> FileReference.path(1). A file shipped in the
bundle that no entry names here is exactly what bundletool rejects.
+
+ Every one of those numbers has a plausible wrong neighbour (config_value 5 is
+ overlayable_item, ConfigValue field 3 is RESERVED, Value field 1 is source), and
+ a walk that shares a mistake with the writer confirms nothing. They come from
+ aapt2's Resources.proto; bundletool, which reads the same schema, is the
+ authority the CI step defers to.
"""
paths = []
for package in decode_message(table).get(2, []):
for type_ in decode_message(package).get(3, []):
for entry in decode_message(type_).get(3, []):
for config_value in decode_message(entry).get(6, []):
- for value in decode_message(config_value).get(3, []):
+ for value in decode_message(config_value).get(2, []):
for item in decode_message(value).get(4, []):
for reference in decode_message(item).get(5, []):
for raw in decode_message(reference).get(1, []):
@@ -229,6 +235,7 @@ def verify(path):
"manifest": manifest,
"resourceFiles": (resource_files(zf.read("base/resources.pb"))
if "base/resources.pb" in names else []),
+ "resFiles": sorted(n[len("base/"):] for n in names if n.startswith("base/res/")),
"hasDex": any(n.startswith("base/dex/") for n in names),
"libs": sorted(n for n in names if n.startswith("base/lib/")),
"assets": sum(1 for n in names if n.startswith("base/assets/")),
diff --git a/build-tools/utils/androidResources.js b/build-tools/utils/androidResources.js
index e8eef0f0f..312d69ec9 100644
--- a/build-tools/utils/androidResources.js
+++ b/build-tools/utils/androidResources.js
@@ -157,14 +157,15 @@ function binaryTable() {
* correct, just not density-aware.
*/
function protoTable() {
- // Field numbers are Resources.proto's, and the two that carry the value are the
- // ones with a plausible wrong answer next door: Value.item is 4 (1 is `source`)
- // and Entry.config_value is 6 (5 is `overlayable_item`). Writing either neighbour
- // still parses — into a table that names no file, which is how bundletool sees a
- // bundle whose icon nothing references.
+ // Field numbers are Resources.proto's, and every one on the way down to the path
+ // has a plausible wrong answer next door: Entry.config_value is 6 (5 is
+ // `overlayable_item`), ConfigValue.value is 2 (3 is RESERVED), Value.item is 4
+ // (1 is `source`). Any of those still encodes and still parses — into a table
+ // that names no file, which is how bundletool sees a bundle whose icon nothing
+ // references. They are checked against the schema, not against our own reader.
const fileReference = message(bytesField(1, ICON_PATH), varintField(2, 1)); // Type.PNG
const value = message(bytesField(4, message(bytesField(5, fileReference))));
- const configValue = message(bytesField(3, value));
+ const configValue = message(bytesField(2, value));
const entry = message(
bytesField(1, message(varintField(1, ENTRY_ID))),
bytesField(2, 'ic_launcher'),
diff --git a/desktop/tests/android-aab.test.ts b/desktop/tests/android-aab.test.ts
index cf47baec6..de9eaab76 100644
--- a/desktop/tests/android-aab.test.ts
+++ b/desktop/tests/android-aab.test.ts
@@ -112,7 +112,7 @@ function build(): string {
function verify(aab: string): {
entries: number; signedEntries: number; bundletoolVersion: string;
uncompressedGlobs: string[]; manifest: Element; hasDex: boolean;
- libs: string[]; assets: number; resourceFiles: string[];
+ libs: string[]; assets: number; resourceFiles: string[]; resFiles: string[];
} {
return JSON.parse(execFileSync('python3', [VERIFIER, aab], { encoding: 'utf8' }));
}
@@ -202,18 +202,19 @@ describe('assembling an App Bundle', () => {
expect(entries).toContain('base/res/mipmap-xxxhdpi/ic_launcher.png');
expect(entries).toContain('base/resources.pb');
- const { manifest, resourceFiles } = verify(build());
+ const { manifest, resourceFiles, resFiles } = verify(build());
const application = find(manifest, 'application')!;
expect(attr(application, 'icon')).toMatchObject({
value: '@mipmap/ic_launcher',
compiled: { ref: 0x7f010000 },
});
- // The other half of the reference: the table has to NAME the file, or
- // bundletool rejects the bundle for shipping a resource nothing points at.
- // Reaching it is a walk over field numbers a wrong guess still parses past,
- // so it is asserted here rather than left to the JVM step below.
- expect(resourceFiles).toContain('res/mipmap-xxxhdpi/ic_launcher.png');
+ // The other half of the reference, and bundletool's own rule: every file
+ // under res/ has to be named by the table. Asserted as that relation rather
+ // than as one expected path, so a resource added later without a table entry
+ // fails here too — the JVM step below is the authority, not the only check.
+ expect(resourceFiles.slice().sort()).toEqual(resFiles.slice().sort());
+ expect(resFiles).toContain('res/mipmap-xxxhdpi/ic_launcher.png');
});
it('fails verification once an entry changes under the signature', () => {