Skip to content

build: raise the default minSdk to 24 - #2135

Draft
edusperoni wants to merge 1 commit into
mainfrom
build/min-sdk-24
Draft

edusperoni wants to merge 1 commit into
mainfrom
build/min-sdk-24

Conversation

@edusperoni

@edusperoni edusperoni commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Since July, Google Play services and Firebase libraries require minSdk 24, so most apps already declare it. This PR raises the runtime's default minSdk to 24 as well and removes the code that only existed for API 21–23.

Current behavior. NS_DEFAULT_MIN_SDK_VERSION=21 sets the minSdk of the runtime library and is the default for every app's build.gradle. package.json reports version_info.minSdk/ndkApiLevel as 21. The runtime carries fallbacks for API 21–23:

  • the android.view.Choreographer frame-callback bridge (com.tns.FrameCallbacks)
  • a dlsym lookup of AChoreographer
  • SDK_INT >= 24 gates around default-method handling
  • DexPathList reflection in place of BaseDexClassLoader.addDexPath

New behavior.

  • NS_DEFAULT_MIN_SDK_VERSION=24 (test-app/gradle.properties, which ships to apps). version_info.minSdk and ndkApiLevel in package.json are now 24.
  • Optimized links pass -Wl,--pack-dyn-relocs=android, Android's packed relocation format, which the loader reads from API 23. At API 23+, clang also links with --hash-style=gnu, which drops the SysV .hash section.
  • FrameCallbacks.cpp links AChoreographer_getInstance, AChoreographer_postFrameCallback and AChoreographer_postFrameCallbackDelayed directly. The API 29 *64 variants are still resolved with dlsym and preferred when present, exactly as before. The Java fallback (FrameCallbacks.java), its JNI entry point, and the debug-only __setFrameCallbackImpl hook plus the specs that drove it are removed.
  • The SDK_INT >= 24 gates in InterfaceProxyHandler, DexFactory.generateDex and Runtime.getDefaultMethodNames are removed. So is the pre-24 appendDexElements reflection, since addDexPath is always available now.

On API 24+ devices, every removed branch was already the one not taken, so runtime behavior there is unchanged.

What apps see

  • Apps that declare minSdk 21–23 (in app.gradle or the manifest) now fail the manifest merge and must raise minSdk to 24. Verified by building the test app with -PminSdk=23:
    uses-sdk:minSdkVersion 23 cannot be smaller than version 24 declared in library [:runtime] ...
    Suggestion: use a compatible library with a minSdk of at most 23,
        or increase this project's minSdk version to at least 24,
        or use tools:overrideLibrary="com.tns.android_runtime" to force usage (may lead to runtime failures)
    
  • Apps that declare no minSdk silently become minSdk 24. Google Play stops offering their updates to API 21–23 devices.
  • tools:overrideLibrary past this is unsupported. libNativeScript.so will not load below 24: it has packed relocations and only a GNU hash table, which API 21–22 cannot read, and it imports AChoreographer_* symbols, which API 23 lacks.
  • AGP packages native libraries differently at minSdk ≥ 23. useLegacyPackaging now defaults to false, so .so files are stored uncompressed and page-aligned in the APK and are loaded from it in place. They are no longer extracted to nativeLibraryDir.
    • The universal test APK grows from 43 MB to 110 MB on disk. For apps installed from Play, the download stays compressed, and the installed footprint shrinks because nothing is extracted.
    • The runtime does not depend on extraction: it passes nativeLibraryDir through but never reads files from it, and the suite passes this way.
    • Plugins or apps that exec or open files from nativeLibraryDir would need packaging { jniLibs { useLegacyPackaging = true } }.

Size (optimized release, -Poptimized RelWithDebInfo, llvm-strip --strip-all, NDK r29)

ABI stripped .so gzip -9 dynamic relocations (.rela.dyn/.rel.dyn)
arm64-v8a 24,511,312 → 23,544,592 (−944 KB, −3.9%) 8,768,754 → 8,652,894 (−113 KB) 1,098,144 → 153,106 (−86%)
armeabi-v7a 17,461,784 → 17,097,200 (−356 KB, −2.1%) 8,013,467 → 7,946,155 (−66 KB) 374,888 → 28,345 (−92%)
x86 26,616,336 → 26,255,848 (−352 KB, −1.4%) 10,045,327 → 9,977,941 (−66 KB) 373,640 → 28,277 (−92%)
x86_64 26,035,032 → 25,232,152 (−784 KB, −3.1%) 9,191,694 → 9,098,033 (−91 KB) 942,144 → 141,452 (−85%)

llvm-readelf -d on the new arm64 library shows ANDROID_RELA/ANDROID_RELASZ and GNU_HASH only, with no HASH.

Performance

Measured on an arm64 phone (Samsung SM-G780G, Android 13), optimized release APKs. Base is current main (minSdk 21); new is this branch (minSdk 24).

Library load. dlopen(libNativeScript.so, RTLD_NOW) of the stripped library, each in a fresh process, 20 interleaved runs (1 warm-up round dropped):

main (minSdk 21) this PR (minSdk 24)
arm64-v8a 58.24 ms (IQR 57.75–58.39) 58.18 ms (IQR 57.79–58.58)
armeabi-v7a (32-bit process) 61.16 ms (IQR 60.63–61.61) 61.08 ms (IQR 60.87–61.25)

The packed format changes how relocations are encoded, not how many there are, so load time is unchanged. The win is size.

Cold start. am start -W TotalTime after am force-stop. 3 interleaved install blocks per build, each with 1 dropped launch and 5 measured (n=15). The app runs a trivial script at startup.

median IQR min–max
main (minSdk 21) 180 ms 176–183 173–200
this PR (minSdk 24) 179 ms 172–187 171–191

JNI bridge (debug.ns.jnibench, 2 interleaved blocks × 2 runs, compared run against matching run because the phone alternates between two clock states; median of the 4 per-run deltas):

row main this PR Δ
static.noop() 105 ns 104 ns −1.3%
static.add(int,int) 187 ns 185 ns −0.9%
instance.getInt() 239 ns 239 ns 0.0%
instance.echo(String) 687 ns 667 ns −2.9%
field.get int 162 ns 161 ns −0.3%
callback.twoInts(int,int) +0.8% (noisy)

Per-call cost is unchanged. The callback and contention rows swing by tens of percent between clock states in either build.

Follow-ups, not in this PR

  • In test-app/runtime/CMakeLists.txt we pass -mstackrealign ourselves on every ABI. Its only purpose is an x86 bug below API 24, so at minSdk 24 it is dead. The companion PR that keeps the NDK default flags already stops passing it, and leaves it to the NDK toolchain, which only adds it for x86 below API 24. Once both PRs land, x86 loses it too. This PR does not touch it, so the two stay independent.
  • The v8-buildscripts min-sdk patch hunk can be dropped there once this lands. That is a separate repo and is not touched here.
  • Test-side branches that only run when the app is dexed below minSdk 24 become dead in the test app. These are the isDesugared() expectations and the SDK_INT < 24 early returns in testInterfaceDefaultMethodOverrides.js, testInterfaceProxies.js, testAppModuleBindings.js, testInterfaceExtendClasses.js, testRuntimeGenerationReport.js and testRequestAnimationFrame.js. They are left as they are, so they can be pruned separately.

Does your commit message include the wording below to reference a specific issue in this repo?

No.

Related Pull Requests

Does your pull request have unit tests?

The existing frame-callback specs cover the remaining native path. The two specs that forced the removed Java path are gone. Verification:

  • Full suite (./gradlew runtestsAndVerifyResults -Pabis=arm64-v8a) on an arm64 API 36 emulator: 1771 specs, 0 failures. That is 1773 on main minus the two removed Java-path specs.
  • Manifest merge with -PminSdk=23 fails as quoted above.
  • The optimized release APK, which carries the packed relocations, was installed and run on an arm64 phone (Android 13) for the cold-start and JNI benchmarks above. The stripped armeabi-v7a library was dlopened in a 32-bit process on the same phone.

Google Play services and Firebase libraries require minSdk 24, so most
apps already declare it. NS_DEFAULT_MIN_SDK_VERSION, which the runtime
library and every app's build.gradle default to, goes from 21 to 24, as
do the minSdk/ndkApiLevel entries in package.json's version_info.

With 24 as the floor:
- Optimized links pass -Wl,--pack-dyn-relocs=android (the loader reads
  the packed format from API 23); the dynamic relocation table shrinks
  from 1,098,144 to 153,106 bytes on arm64-v8a. clang also stops
  emitting the SysV .hash section next to .gnu.hash.
- AChoreographer_getInstance/postFrameCallback(Delayed) are linked
  directly instead of through dlsym. Only the API 29 64-bit variants
  are still resolved at run time.
- The android.view.Choreographer fallback (com.tns.FrameCallbacks), its
  JNI entry point and the debug-only __setFrameCallbackImpl hook that
  tested it are removed.
- The SDK_INT >= 24 gates on default-method handling
  (InterfaceProxyHandler, DexFactory, Runtime.getDefaultMethodNames) and
  the pre-24 DexPathList reflection behind injectDexIntoClassLoader are
  removed; addDexPath is always available.

Behavior on API 24+ devices is unchanged.

Apps that declare a minSdk of 21-23 now fail the manifest merge and
must raise it; apps that declare none become minSdk 24.
@coderabbitai

coderabbitai Bot commented Nov 21, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant