ReviewOS

also looking at this

craft-native/craft

fix(android): make every Zig decline speak, and prove Zig answers

#205
Merged glennmichael123 wants to merge fix/android-zig-serves into main
8 files +616 -255
packages/zig/src/bridge_android_device.zigmodified+16-4
Changes to packages/zig/src/bridge_android_device.zig
@@ -373,11 +373,23 @@ fn readPackageInfo(allocator: std.mem.Allocator, j: Jni, activity: jobject, sdk:
373373 errdefer allocator.free(version_name);
374374 allocator.free(fallback.version_name);
375375
376 // API 28 split the build number in two: `longVersionCode` is the whole
377 // value, `versionCode` its low 32 bits. Reading the wrong one on a modern
378 // app truncates rather than failing.
376 // API 28 split the build number in two: `getLongVersionCode()` is the
377 // whole value, `versionCode` its low 32 bits. Reading the wrong one on a
378 // modern app truncates rather than failing.
379 //
380 // A method, not a field. The Kotlin shim writes `.longVersionCode`, which
381 // Kotlin compiles to a call to the getter — there is no `longVersionCode`
382 // field on PackageInfo at all. This used to ask for one, and the first
383 // time it ran on a device, every call ended in
384 //
385 // java.lang.NoSuchFieldError: no "J" field "longVersionCode" in class
386 // "Landroid/content/pm/PackageInfo;" or its superclasses
387 //
388 // and fell through to the shim. It had never run anywhere before, because
389 // no generated app had ever loaded this library. `versionCode` below is a
390 // genuine public field, deprecated but present.
379391 const build: i64 = if (sdk >= 28)
380 try j.longField(info, try j.fieldId(info_cls, "longVersionCode", "J"))
392 try j.callLongMethod(info, try j.methodId(info_cls, "getLongVersionCode", "()J"))
381393 else
382394 try j.intField(info, try j.fieldId(info_cls, "versionCode", "I"));
383395