Skip to content

Commit 4aece83

Browse files
committed
build: raise the default minSdk to 24
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.
1 parent 9a514a7 commit 4aece83

11 files changed

Lines changed: 92 additions & 377 deletions

File tree

‎docs/performance.md‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,8 @@ __postFrameCallback((frameTimeNanos, performanceMillis) => { … });
7575
frames on the very clock the time origin is captured on, so the mapping is
7676
exact rather than an approximation resampled in JS.
7777

78-
Two implementations sit behind that one surface: the NDK's `AChoreographer`
79-
(API 24+, resolved with `dlsym`) and `android.view.Choreographer` through
80-
`com.tns.FrameCallbacks` for API 21–23, where the NDK API does not exist.
81-
Scheduling is per calling thread, so a worker schedules against its own looper.
82-
Both paths produce the same two arguments with the same exactness.
78+
Frames come from the NDK's `AChoreographer`. Scheduling is per calling thread,
79+
so a worker schedules against its own looper.
8380

8481
## Deviations from the specs
8582

‎package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
"gradle": "8.14.3",
1515
"gradleAndroid": "8.12.1",
1616
"ndk": "r29",
17-
"ndkApiLevel": "21",
18-
"minSdk": "21",
17+
"ndkApiLevel": "24",
18+
"minSdk": "24",
1919
"compileSdk": "35",
2020
"buildTools": "35.0.0",
2121
"kotlin": "2.0.0"

‎test-app/app/src/main/assets/app/tests/testPostFrameCallback.js‎

Lines changed: 49 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -235,97 +235,64 @@ describe("requestAnimationFrame", function () {
235235
});
236236
});
237237

238-
// The two implementations behind __postFrameCallback (NDK AChoreographer,
239-
// android.view.Choreographer for API < 24) must be indistinguishable from JS.
240-
// A modern device always selects the NDK one, so the Java bridge is only
241-
// reachable through __setFrameCallbackImpl, which debug runtimes expose for
242-
// exactly this.
243238
describe("frame callback timestamps", function () {
244239
const defaultWaitTime = 300;
245-
const impls = ["native", "java"];
246240

247-
afterEach(() => {
248-
if (typeof global.__setFrameCallbackImpl === "function") {
249-
global.__setFrameCallbackImpl("auto");
250-
}
251-
});
252-
253-
function withImpl(impl) {
254-
if (typeof global.__setFrameCallbackImpl !== "function") {
255-
return impl === "native";
256-
}
257-
return global.__setFrameCallbackImpl(impl) === impl;
258-
}
259-
260-
impls.forEach((impl) => {
261-
describe(impl + " implementation", function () {
262-
it("passes the raw frame time and a performance-timeline timestamp", (done) => {
263-
if (!withImpl(impl)) {
264-
pending("this runtime cannot select the " + impl + " implementation");
265-
return;
266-
}
267-
268-
global.__postFrameCallback((frameTimeNanos, performanceMillis) => {
269-
const now = performance.now();
270-
271-
expect(typeof frameTimeNanos).toBe("number");
272-
expect(typeof performanceMillis).toBe("number");
241+
it("passes the raw frame time and a performance-timeline timestamp", (done) => {
242+
global.__postFrameCallback((frameTimeNanos, performanceMillis) => {
243+
const now = performance.now();
273244

274-
// Uptime-scale nanoseconds, not epoch-scale milliseconds.
275-
expect(frameTimeNanos).toBeGreaterThan(1e9);
276-
expect(frameTimeNanos / 1e6).toBeLessThan(Date.now());
245+
expect(typeof frameTimeNanos).toBe("number");
246+
expect(typeof performanceMillis).toBe("number");
277247

278-
// The frame is stamped just before the callback runs, so its
279-
// timeline position sits a frame or two behind the reading taken
280-
// inside it, never ahead of it.
281-
expect(performanceMillis).toBeGreaterThan(0);
282-
expect(performanceMillis).not.toBeGreaterThan(now);
283-
expect(now - performanceMillis).toBeLessThan(250);
248+
// Uptime-scale nanoseconds, not epoch-scale milliseconds.
249+
expect(frameTimeNanos).toBeGreaterThan(1e9);
250+
expect(frameTimeNanos / 1e6).toBeLessThan(Date.now());
284251

285-
// Both arguments describe the same instant, so their difference is
286-
// the timeline's monotonic origin. System.nanoTime() is on that same
287-
// clock, so the pair (nanoTime, now) must yield the same origin --
288-
// this is what would break if either argument moved off the base.
289-
// The two clocks cannot be read at once, so nanoTime is bracketed
290-
// and compared against the midpoint: the tolerance then only has to
291-
// cover the sampling window, not whatever pause lands between them.
292-
const beforeNow = performance.now();
293-
const sampledNanos = java.lang.System.nanoTime();
294-
const afterNow = performance.now();
295-
const originFromFrame = frameTimeNanos / 1e6 - performanceMillis;
296-
const originFromClock = sampledNanos / 1e6 - (beforeNow + afterNow) / 2;
297-
expect(Math.abs(originFromFrame - originFromClock)).toBeLessThan(
298-
5 + (afterNow - beforeNow)
299-
);
300-
done();
301-
});
302-
});
252+
// The frame is stamped just before the callback runs, so its
253+
// timeline position sits a frame or two behind the reading taken
254+
// inside it, never ahead of it.
255+
expect(performanceMillis).toBeGreaterThan(0);
256+
expect(performanceMillis).not.toBeGreaterThan(now);
257+
expect(now - performanceMillis).toBeLessThan(250);
303258

304-
it("advances across consecutive frames", (done) => {
305-
if (!withImpl(impl)) {
306-
pending("this runtime cannot select the " + impl + " implementation");
307-
return;
308-
}
259+
// Both arguments describe the same instant, so their difference is
260+
// the timeline's monotonic origin. System.nanoTime() is on that same
261+
// clock, so the pair (nanoTime, now) must yield the same origin --
262+
// this is what would break if either argument moved off the base.
263+
// The two clocks cannot be read at once, so nanoTime is bracketed
264+
// and compared against the midpoint: the tolerance then only has to
265+
// cover the sampling window, not whatever pause lands between them.
266+
const beforeNow = performance.now();
267+
const sampledNanos = java.lang.System.nanoTime();
268+
const afterNow = performance.now();
269+
const originFromFrame = frameTimeNanos / 1e6 - performanceMillis;
270+
const originFromClock = sampledNanos / 1e6 - (beforeNow + afterNow) / 2;
271+
expect(Math.abs(originFromFrame - originFromClock)).toBeLessThan(
272+
5 + (afterNow - beforeNow)
273+
);
274+
done();
275+
});
276+
});
309277

310-
const frames = [];
311-
const callback = (frameTimeNanos, performanceMillis) => {
312-
frames.push({ nanos: frameTimeNanos, millis: performanceMillis });
313-
if (frames.length === 1) {
314-
global.__postFrameCallback(callback);
315-
}
316-
};
278+
it("advances across consecutive frames", (done) => {
279+
const frames = [];
280+
const callback = (frameTimeNanos, performanceMillis) => {
281+
frames.push({ nanos: frameTimeNanos, millis: performanceMillis });
282+
if (frames.length === 1) {
317283
global.__postFrameCallback(callback);
284+
}
285+
};
286+
global.__postFrameCallback(callback);
318287

319-
setTimeout(() => {
320-
expect(frames.length).toBe(2);
321-
expect(frames[1].nanos).not.toBeLessThan(frames[0].nanos);
322-
expect(frames[1].millis).not.toBeLessThan(frames[0].millis);
323-
// The origin the two arguments imply is a constant of the isolate.
324-
const origin = (f) => f.nanos / 1e6 - f.millis;
325-
expect(Math.abs(origin(frames[1]) - origin(frames[0]))).toBeLessThan(1);
326-
done();
327-
}, defaultWaitTime);
328-
});
329-
});
288+
setTimeout(() => {
289+
expect(frames.length).toBe(2);
290+
expect(frames[1].nanos).not.toBeLessThan(frames[0].nanos);
291+
expect(frames[1].millis).not.toBeLessThan(frames[0].millis);
292+
// The origin the two arguments imply is a constant of the isolate.
293+
const origin = (f) => f.nanos / 1e6 - f.millis;
294+
expect(Math.abs(origin(frames[1]) - origin(frames[0]))).toBeLessThan(1);
295+
done();
296+
}, defaultWaitTime);
330297
});
331298
});

‎test-app/gradle.properties‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ android.useAndroidX=true
2121
# Default versions used throughout the gradle configurations
2222
NS_DEFAULT_BUILD_TOOLS_VERSION=35.0.0
2323
NS_DEFAULT_COMPILE_SDK_VERSION=35
24-
NS_DEFAULT_MIN_SDK_VERSION=21
24+
NS_DEFAULT_MIN_SDK_VERSION=24
2525
NS_DEFAULT_ANDROID_BUILD_TOOLS_VERSION=8.13.2
2626
# R8 8.x cannot read Kotlin 2.4 metadata (needs 9.1.29+), so the AGP-bundled R8 is overridden.
2727
NS_DEFAULT_R8_VERSION=9.1.43

‎test-app/runtime/CMakeLists.txt‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,4 +317,9 @@ find_library(system-android android)
317317

318318
# Command info: https://cmake.org/cmake/help/v3.4/command/target_link_libraries.html
319319
# Specifies libraries CMake should link to your target library.
320-
target_link_libraries(NativeScript ${system-log} ${system-z} ${system-android})
320+
target_link_libraries(NativeScript ${system-log} ${system-z} ${system-android})
321+
322+
if (OPTIMIZED_BUILD OR OPTIMIZED_WITH_INSPECTOR_BUILD)
323+
# Android's packed relocation format, which the loader reads from API 23.
324+
target_link_options(NativeScript PRIVATE "-Wl,--pack-dyn-relocs=android")
325+
endif ()

0 commit comments

Comments
 (0)