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.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
fix(android): the bundle's resource table names the icon, so bundletool takes it
yhh0748b06e149c
diff --git a/build-tools/tests/verify-aab.py b/build-tools/tests/verify-aab.pyindex 1ab2f91d0..61632d889 100644--- a/build-tools/tests/verify-aab.py+++ b/build-tools/tests/verify-aab.py@@ -188,6 +188,28 @@ def _verify_pkcs7(block, signed_content):raise SystemExit("the JAR signature does not verify against the certificate")+def resource_files(table):+ """Every file path the resource table actually names.++ 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) ->+ 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.+ """+ 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 item in decode_message(value).get(4, []):+ for reference in decode_message(item).get(5, []):+ for raw in decode_message(reference).get(1, []):+ paths.append(raw.decode())+ return paths++def verify(path):with zipfile.ZipFile(path) as zf:names = zf.namelist()@@ -205,6 +227,8 @@ def verify(path):"bundletoolVersion": decode_message(config[1][0])[2][0].decode(),"uncompressedGlobs": [g.decode() for g in decode_message(config[3][0])[1]],"manifest": manifest,+ "resourceFiles": (resource_files(zf.read("base/resources.pb"))+ if "base/resources.pb" in names else []),"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.jsindex 743d6ee1b..e8eef0f0f 100644--- a/build-tools/utils/androidResources.js+++ b/build-tools/utils/androidResources.js@@ -157,13 +157,18 @@ 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.const fileReference = message(bytesField(1, ICON_PATH), varintField(2, 1)); // Type.PNG- const value = message(bytesField(1, message(bytesField(5, fileReference))));+ const value = message(bytesField(4, message(bytesField(5, fileReference))));const configValue = message(bytesField(3, value));const entry = message(bytesField(1, message(varintField(1, ENTRY_ID))),bytesField(2, 'ic_launcher'),- bytesField(5, configValue),+ bytesField(6, configValue),);const type = message(bytesField(1, message(varintField(1, TYPE_ID))),diff --git a/desktop/tests/android-aab.test.ts b/desktop/tests/android-aab.test.tsindex 3bf1c9a31..cf47baec6 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;+ libs: string[]; assets: number; resourceFiles: string[];} {return JSON.parse(execFileSync('python3', [VERIFIER, aab], { encoding: 'utf8' }));}@@ -202,12 +202,18 @@ describe('assembling an App Bundle', () => {expect(entries).toContain('base/res/mipmap-xxxhdpi/ic_launcher.png');expect(entries).toContain('base/resources.pb');- const { manifest } = verify(build());+ const { manifest, resourceFiles } = 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');});it('fails verification once an entry changes under the signature', () => {