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): build against the API level the manifest declares

esengine426dfa3d0e23
diff --git a/.github/workflows/android-compat.yml b/.github/workflows/android-compat.yml
index bfdcae4f3..70f652df2 100644
--- a/.github/workflows/android-compat.yml
+++ b/.github/workflows/android-compat.yml
@@ -167,7 +167,12 @@ jobs:
if [ -z "$WANT" ] || [ "$WANT" = 'auto' ]; then
if [ "$GITHUB_EVENT_NAME" = 'pull_request' ]; then
CHANGED=$(gh pr diff '${{ github.event.pull_request.number }}' --name-only)
- if echo "$CHANGED" | grep -qE '^(native/|toolchain\.manifest\.json)'; then
+ # build-tools/ counts: the API level the host compiles against is a
+ # DEFAULT in build-tools, not a value in native/. The change that fixed
+ # the Android 10 crash touched nothing under native/, so a rule that
+ # watched only native/ would have tested the old released binary and
+ # reported the fix as not working.
+ if echo "$CHANGED" | grep -qE '^(native/|build-tools/|toolchain\.manifest\.json)'; then
WANT=head
echo "this PR touches the native host — the template must be built from it"
else
diff --git a/build-tools/cli.js b/build-tools/cli.js
index fe0e5309a..9332042a1 100644
--- a/build-tools/cli.js
+++ b/build-tools/cli.js
@@ -167,7 +167,7 @@ program
.option('--dawn-build <dir>', 'Dawn build dir for this target (default: <dawn>/out-<target>, built if absent)')
.option('--quickjs <dir>', 'QuickJS-ng source dir (default: the pinned checkout; or ESTELLA_QUICKJS_DIR)')
.option('--abi <abi>', 'Android ABI', 'arm64-v8a')
- .option('--platform <platform>', 'Android platform', 'android-33')
+ .option('--platform <platform>', 'Android platform', 'android-29')
.option('--ios-min <version>', 'iOS deployment target', '17.0')
.option('--simulator', 'iOS: build the simulator slice (needs a simulator Dawn)', false)
.option('--package', 'Assemble the app around --content from the installed runtime template: Android a signed APK, iOS an Xcode project', false)
diff --git a/build-tools/tasks/native.js b/build-tools/tasks/native.js
index fec2d02bc..0831f24d8 100644
--- a/build-tools/tasks/native.js
+++ b/build-tools/tasks/native.js
@@ -312,7 +312,14 @@ function quickjsDir(options) {
const fwd = (p) => p.replace(/\\/g, '/');
async function buildAndroidHost(options) {
- const { abi = 'arm64-v8a', platform = 'android-33' } = options;
+ // The platform MUST equal the manifest's minSdkVersion. The NDK emits a weak
+ // reference for an API newer than the target and a strong one otherwise, and
+ // `__builtin_available` is compiled out in the second case — so building above
+ // the declared floor turns every guard into dead code and every guarded symbol
+ // into a load-time requirement. At android-33 that shipped a host which could
+ // not dlopen below API 31: `cannot locate symbol APerformanceHint_getManager`,
+ // on Android 10 and 11, before a line of our code ran.
+ const { abi = 'arm64-v8a', platform = 'android-29' } = options;
const rootDir = config.paths.root;
const sdk = requireSdk();
diff --git a/build-tools/tasks/nativeDeps.js b/build-tools/tasks/nativeDeps.js
index bf197606a..027ec349c 100644
--- a/build-tools/tasks/nativeDeps.js
+++ b/build-tools/tasks/nativeDeps.js
@@ -145,7 +145,7 @@ export async function ensureDawnBuild(options) {
? [
`-DCMAKE_TOOLCHAIN_FILE=${path.join(options.ndk, 'build', 'cmake', 'android.toolchain.cmake')}`,
`-DANDROID_ABI=${options.abi || 'arm64-v8a'}`,
- `-DANDROID_PLATFORM=${options.androidPlatform || 'android-33'}`,
+ `-DANDROID_PLATFORM=${options.androidPlatform || 'android-29'}`,
'-DANDROID_STL=c++_shared',
'-DDAWN_ENABLE_VULKAN=ON', '-DDAWN_ENABLE_METAL=OFF',
// Shared on Android (the APK ships the .so); static on iOS (an app
diff --git a/build-tools/tasks/nativeTemplateEmit.js b/build-tools/tasks/nativeTemplateEmit.js
index 0dd9fbdad..1ce6293ab 100644
--- a/build-tools/tasks/nativeTemplateEmit.js
+++ b/build-tools/tasks/nativeTemplateEmit.js
@@ -200,7 +200,7 @@ export async function emitNativeTemplate(options) {
spineVersion: options.spineVersion || '4.2',
...(platform === 'ios' ? { deploymentTarget: options.deploymentTarget || '17.0' } : {}),
...(platform === 'android'
- ? { androidPlatform: options.androidPlatform || 'android-33', abis: templateAbis(dir) }
+ ? { androidPlatform: options.androidPlatform || 'android-29', abis: templateAbis(dir) }
: {}),
});
diff --git a/build-tools/utils/apk.js b/build-tools/utils/apk.js
index 29447266a..25f9937de 100644
--- a/build-tools/utils/apk.js
+++ b/build-tools/utils/apk.js
@@ -28,7 +28,7 @@ import { fillTemplate, androidScreenOrientation } from './nativeApp.js';
* smaller page size also divides. */
const PAGE_ALIGNMENT = 16384;
-/** APK Signature Scheme v2. minSdk 26 is well past the API 24 that introduced it,
+/** APK Signature Scheme v2. minSdk 29 is well past the API 24 that introduced it,
* so v1 (JAR signing) would be dead weight — and its PKCS#7 is the only part of
* APK signing that is genuinely hard to write. */
const V2_BLOCK_ID = 0x7109871a;
diff --git a/build-tools/utils/gradleProject.js b/build-tools/utils/gradleProject.js
index 6c0a84135..830537fd2 100644
--- a/build-tools/utils/gradleProject.js
+++ b/build-tools/utils/gradleProject.js
@@ -54,7 +54,7 @@ export function gradleManifest(templateXml, app) {
HAS_CODE: 'true',
});
- const minSdk = Number(/android:minSdkVersion="(\d+)"/.exec(filled)?.[1] ?? 26);
+ const minSdk = Number(/android:minSdkVersion="(\d+)"/.exec(filled)?.[1] ?? 29);
const targetSdk = Number(/android:targetSdkVersion="(\d+)"/.exec(filled)?.[1] ?? 33);
const xml = filled
diff --git a/desktop/tests/android-project.test.ts b/desktop/tests/android-project.test.ts
index 9a591a5e7..01c9e130d 100644
--- a/desktop/tests/android-project.test.ts
+++ b/desktop/tests/android-project.test.ts
@@ -110,7 +110,7 @@ describe('the Android Studio project an export writes', () => {
expect(gradle).toContain('versionCode = 7');
expect(gradle).toContain('versionName = "1.2"');
// Taken from the manifest template rather than restated, so the two agree.
- expect(gradle).toContain('minSdk = 26');
+ expect(gradle).toContain('minSdk = 29');
expect(gradle).toContain('targetSdk = 33');
});
@@ -163,7 +163,7 @@ describe('the Android Studio project an export writes', () => {
describe('gradleManifest', () => {
it('reads the SDK levels it strips, so the build script can state them', () => {
const { minSdk, targetSdk } = gradleManifest(readFileSync(MANIFEST_TEMPLATE, 'utf8'), APP);
- expect(minSdk).toBe(26);
+ expect(minSdk).toBe(29);
expect(targetSdk).toBe(33);
});
});
diff --git a/native/android/host/AndroidManifest.xml.in b/native/android/host/AndroidManifest.xml.in
index b173606c8..787912588 100644
--- a/native/android/host/AndroidManifest.xml.in
+++ b/native/android/host/AndroidManifest.xml.in
@@ -8,12 +8,22 @@
hard requirement, and the config changes the host handles rather than being
restarted for. `hasCode` follows whether the Java shim compiled — the game is
native, and the only Java in the package is the IME's side of a text field.
+
+ minSdkVersion 29, and the NDK MUST build against the same number (`--platform`,
+ build-tools/tasks/native.js). The host calls AFontMatcher_create unguarded and
+ that is API 29, so nothing below it could ever have run; 26 promised three
+ releases the code never supported. The equality is what makes the availability
+ guards work: the NDK emits a weak reference only for an API newer than the
+ build target, so building above the declared floor compiles every
+ `__builtin_available` out and turns its symbol into a load-time requirement.
+ Built at android-33, the released host could not dlopen below API 31 —
+ "cannot locate symbol APerformanceHint_getManager" on Android 10 and 11.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="@APP_ID@"
android:versionCode="@VERSION_CODE@"
android:versionName="@VERSION_NAME@">
- <uses-sdk android:minSdkVersion="26" android:targetSdkVersion="33" />
+ <uses-sdk android:minSdkVersion="29" android:targetSdkVersion="33" />
<uses-feature android:name="android.hardware.vulkan.version" android:version="0x400003" android:required="true" />
<application android:label="@APP_NAME@" android:icon="@mipmap/ic_launcher"
android:hasCode="@HAS_CODE@" android:extractNativeLibs="false">