Skip to content

fix: verify native and plugin APKs with aapt2 - #6670

Merged
janicduplessis merged 1 commit into
mainfrom
fix/6668-aapt2-badging
Nov 29, 2026
Merged

janicduplessis merged 1 commit into
mainfrom
fix/6668-aapt2-badging

Conversation

@janicduplessis

Copy link
Copy Markdown
Collaborator

Description

Stim checks every native Android artifact and every APK a project plugin builds with inspectApk, which reads dump badging for the package name, the split= refusal and the native-code ABIs. It ran the legacy aapt, and plugin-android.ts refused a plugin build when the SDK had no aapt.

aapt is strict about attribute value types in a binary manifest. Godot's Android exporter patches the manifest of its prebuilt template and writes android:required and android:version of the Vulkan uses-feature entries as strings, so aapt fails on every Godot export that uses the default renderer:

AndroidManifest.xml:0: error: failed to read attribute 'android:required': attribute is not an integer value

aapt2 reads the same APK, and the device installs it.

Solution

inspectApk and the plugin build's tool check use aapt2 instead of aapt, with the same dump badging <apk> arguments. The refusal texts name aapt2.

No aapt fallback. aapt2 has shipped in every build-tools release since 26.0.0. Stim has no build-tools floor of its own, and it signs with apksigner, which the check already requires. The build-tools that have apksigner but no aapt2 are 24.0.3 to 25.0.3, from 2016 and 2017, and no Android Gradle Plugin that current React Native, Expo or Godot use accepts them. A fallback would need a version-first search, because findBuildTool walks versions newest first and stops at the first match. With ['aapt2', 'aapt'], a newer directory holding only aapt would win and the Godot failure would come back. It would also be a branch that no build-tools on a test machine can exercise. findBuildTool(['aapt2']) still falls back to an older build-tools directory when the newest has no aapt2, for example a partial 36.0.0-rc5 install.

The two tools print the lines Stim parses identically (see the test plan). An existing cache receipt holds the same package and ABIs either way, so cached APKs stay valid. aapt2 prints warn: lines for the Godot APK on stderr. They do not start with package: or native-code:, and the dump exits 0.

scripts/build-compat.json gets a new digest and no STIM_BUILD_COMPAT bump: a worker with either version builds the same artifact, and the change only makes a failing build succeed.

Test plan

Real tools, build-tools 37.0.0 on macOS. The lines inspectApk parses, from each tool's dump badging:

APK aapt aapt2
React Native debug APK, Gradle-built exit 0, package: name='nitrofetch.example' versionCode='1' versionName='1.0' platformBuildVersionName='17' ..., native-code: 'arm64-v8a' identical
Bare React Native release APK, four ABIs exit 0, native-code: 'arm64-v8a' 'armeabi-v7a' 'x86' 'x86_64' identical
Split APK linked by aapt2 link from a manifest with split="config.x86_64" exit 0, package: name='dev.stim.split.probe' versionCode='1' versionName='1' split='config.x86_64' ... identical
Manifest-only APK packaged by aapt package exit 0, package: name='dev.stim.cache.compat' ... identical
Godot 4.7.2 debug export, default renderer, arm64-v8a exit 1, the android:required error above exit 0, package: name='dev.stim.godotcheck' versionCode='1' versionName='1.0.0' ..., native-code: 'arm64-v8a'

The aapt2 of build-tools 30.0.3 and 34.0.0 print the same package: and native-code: lines for the four-ABI APK and the split APK.

End to end, with this branch's build in a scratch Stim home and the Godot project plugin: stim android in a Godot 4.7.2 project with the default renderer exported the APK, passed the check (build ok), installed it on an owned emulator and launched it. The first launch on the freshly booted emulator exited, because a system overlay update recreated the activity before Godot had started. A second stim android on the settled emulator passed the launch check (OK: dev.stim.godotcheck launched). The process stayed alive, running Vulkan 1.2.293 - Forward Mobile.

Tests:

  • native-android-cache.compat.test.ts now builds its fixture APKs with aapt2 link, so the probe needs aapt2, apksigner and keytool. It also checks that a real signed split APK is refused, which no test covered before. Removing the split= check makes this probe fail. pnpm run test:compat packages/stim-cli/src/__tests__/native-android-cache.compat.test.ts passes (2 cases).
  • The SDK fakes in native-android-cache.test.ts (32 passed), plugin-android.test.ts (9 passed) and test/e2e/native-source-worker.e2e.js are renamed from aapt to aapt2. With the old code, these fakes leave no aapt in the SDK.
  • docs/testing.md names aapt2 for the probe.
  • pnpm run format:check, pnpm run lint, pnpm run build, pnpm run typecheck and pnpm run knip pass.

Fixes #6668

aapt rejects a binary manifest attribute whose value type does not match, such as the string android:required that a Godot default-renderer export writes. aapt2 reads the same APK and prints the package and native-code lines identically. Closes #6668
@janicduplessis janicduplessis added area: cli packages/stim-cli, including its README and guide ci-full run the macOS, Windows, Desktop and license jobs on this pull request labels Nov 29, 2026
@janicduplessis

Copy link
Copy Markdown
Collaborator Author

Fresh review of 2b19bcd: no actionable findings.

Real tools. I ran aapt and aapt2 dump badging <apk> from build-tools 37.0.0 and 30.0.3 on every APK on this machine (23 files: Gradle-built React Native and Expo debug and release APKs with one and four ABIs, Godot 4.7.2 debug and release templates, helper APKs with no native code, a framework APK neither tool reads) and on the Godot default-renderer export. I fed the output through the same parser inspectApk uses. On every APK both tools gave the same exit code, package name, split= result and ABI list. On 37.0.0 the package: and native-code: lines were byte-identical. On 30.0.3, aapt2 also prints platformBuildVersionName and platformBuildVersionCode on the package: line, which the parser ignores. The Godot export is the only difference: aapt exits 1 with failed to read attribute 'android:required': attribute is not an integer value, and aapt2 exits 0 with package: name='dev.stim.godotcheck' ... and native-code: 'arm64-v8a'. Its stderr has one warn: line, which does not reach the parser.

I also built APKs with aapt2 link to cover cases no local APK had: a split (split="config.x86_64"), a split with native code, a multiArch APK with three ABIs, and a package name with mixed case, digits and underscores (Dev_1.a2_B.c3). The two 37.0.0 tools printed the same package:, native-code: and alt-native-code: lines for all four. The aapt2 of 30.0.3 and 34.0.0 printed the same lines for the split and multiArch APKs.

No fallback. findBuildTool(['aapt2']) walks build-tools from newest to oldest and skips a directory that lacks the tool. The empty 36.0.0-rc5 directory on this machine is skipped. On Windows, androidBuildToolName('aapt2') resolves to aapt2.exe, which is the name that build-tools ship. I agree with the description's reasoning against a ['aapt2', 'aapt'] fallback. The only difference from the issue's fix idea is that SDKs whose build-tools have apksigner but no aapt2 are refused, and the description states this. It is not a command, flag, setting or default.

Other readers. dumpApkManifest in commands/android/support.ts still prefers aapt, and the local and worker app-id reads use it. It runs dump xmltree, not badging, and aapt dump xmltree reads the Godot export (exit 0), so it does not bring the failure back. The hosted reader in device-host/android-app.ts (#6671) fails the same way it did before this change. It does not need to land with this pull request. No guide, website page, llp/ document or doctor check names aapt as a requirement. The only remaining mentions are a past release note, the xmltree fixtures and the hosted test.

Compatibility. node scripts/build-compat.mjs passes on the new digest. I agree with not bumping STIM_BUILD_COMPAT. A worker and a client on different versions read the same package and ABIs from every APK both tools accept. The only change is that an APK which used to fail the check now passes, and the script's own rule exempts that.

Tests.

  • pnpm test packages/stim-cli/src/__tests__/native-android-cache.test.ts: 32 passed.
  • pnpm test packages/stim-cli/src/__tests__/plugin-android.test.ts: 9 passed.
  • pnpm run test:compat packages/stim-cli/src/__tests__/native-android-cache.compat.test.ts: 2 passed.

The fixtures are still real APKs signed by apksigner, and apksigner verify --print-certs accepts them inside the test. As a mutation check, I removed || /\bsplit=/.test(line) from inspectApk. Both compat cases then failed with promise resolved ... instead of rejecting. I restored the file and the worktree is clean.

Description. It follows the template, matches the diff and links the issue.

Pre-existing, not from this change. The ABI check reads only the native-code: line and ignores alt-native-code:. Both tools print the same lines, so this pull request changes nothing there.

Not verified. Windows and Linux build-tools, and build-tools older than 30.0.3. None are installed here.

@janicduplessis janicduplessis added the review: ai-approved A fresh AI review found nothing left to fix label Nov 29, 2026
@janicduplessis
janicduplessis marked this pull request as ready for review November 29, 2026 02:25
@janicduplessis
janicduplessis merged commit a226700 into main Nov 29, 2026
105 of 113 checks passed
@janicduplessis
janicduplessis deleted the fix/6668-aapt2-badging branch November 29, 2026 02:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: cli packages/stim-cli, including its README and guide ci-full run the macOS, Windows, Desktop and license jobs on this pull request review: ai-approved A fresh AI review found nothing left to fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The APK check rejects a Godot default-renderer APK that aapt2 reads

1 participant