Skip to content

Bump jni to 0.22 and migrate the Android JNI bridge - #485

Merged
Tryanks merged 1 commit into
mainfrom
bump-jni
Sep 20, 2026
Merged

Tryanks merged 1 commit into
mainfrom
bump-jni

Conversation

@Tryanks

@Tryanks Tryanks commented Sep 20, 2026

Copy link
Copy Markdown
Owner

Supersedes #469.

jni 0.22 redesigned its environment and attachment model, so crates/android and crates/platform/gpui-android (excluded from the workspace, built as a path dependency of tcode-android) move together:

  • Native method exports take EnvUnowned and run their JNI work through with_env(...).resolve::<LogErrorAndDefault>(), which also catches panics at the FFI boundary and logs errors instead of the previous silent if let Ok drops. Exports that never touch the environment keep their plain bodies.
  • JavaVM::from_raw is now infallible and registers the singleton; scoped attach_current_thread()/get_env() become closure-based attach_current_thread(|env| …) (a no-op attachment on the Java main thread, which only pushes a local frame). JObject::from_raw now takes the Env.
  • GlobalRef → Global<JObject<'static>> (no longer Clone, so JniObject holds it in an Arc).
  • Method names and signatures use jni_str!/jni_sig! (compile-time MUTF-8/parsed signatures) instead of runtime &str; with_activity takes &'static JNIStr + MethodSignature.
  • Deprecated env.get_string/get_array_length/get_int_array_region become JString::try_to_string, JPrimitiveArray::len/get_region; JString::from(JObject) becomes the checked JString::cast_local.
  • jboolean is bool in jni-sys 0.4, so the u8 conversions go away.

Cargo.lock only re-points the two crates at jni 0.22.4 (already in the graph); jni 0.21.1 stays for its other consumer.

Local evidence (macOS arm64, NDK 27.1.12297006):

  • RUSTFLAGS='-D warnings' CARGO_NDK_PLATFORM=26 cargo ndk -t arm64-v8a check -p tcode-android --locked ✅ (the CI "Mobile and web checks" command)
  • cargo fmt --all --check ✅ (gpui-android formatted with rustfmt --edition 2024 since it is outside the workspace)
  • cargo clippy --workspace --all-targets --locked -- -D warnings ✅
  • cargo build --workspace --locked ✅
  • cargo test -p tcode-android --locked ✅ (no tests)
  • cargo machete ✅

Not covered: no Android device/emulator run; the JNI bridge behaviour (IME, clipboard, camera QR results, preview host) was verified by compilation only.

@Tryanks
Tryanks merged commit 55057f6 into main Sep 20, 2026
6 checks passed
@Tryanks
Tryanks deleted the bump-jni branch September 20, 2026 13:22
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