fix(android): upgrade jni to 0.22.4 for veilid-core compatibility#30
Open
evic2132 wants to merge 3 commits into
Open
fix(android): upgrade jni to 0.22.4 for veilid-core compatibility#30evic2132 wants to merge 3 commits into
evic2132 wants to merge 3 commits into
Conversation
veilid-core v0.5.3 depends on jni 0.22.x and exposes veilid_core_setup_android(EnvUnowned, JObject), which is incompatible with the jni 0.21 API used by the Android bridge. Migrate android_bridge.rs and jni_globals.rs to jni 0.22's EnvUnowned/ Env pattern, and harden build-android.sh NDK auto-detection on macOS without changing the jniLibs output path. Verified: - cargo build --release (host) - cargo ndk build (aarch64-linux-android) - cargo test -- --test-threads=1 (13 passed, 2 ignored)
Add armeabi-v7a for older 32-bit ARM devices to match the Android app's Rust tooling. Skip deprecated 32-bit x86 (i686) emulator ABI.
tripledoublev
requested changes
Jun 18, 2026
tripledoublev
left a comment
Contributor
There was a problem hiding this comment.
Builds clean locally (host cargo build --release + cargo ndk -t arm64-v8a build --release). One blocking issue: startServer falls through after a failed init instead of bailing.
Comment on lines
+70
to
+71
| // Use another new JNIEnv for veilid_core_setup_android | ||
| veilid_core_setup_android(env, context); |
Contributor
There was a problem hiding this comment.
Blocking: if the closure errors, resolve stages a Java exception and returns null/empty, yet we still call into native code and spawn the server with empty paths — return early instead.
Suggested change
| // Use another new JNIEnv for veilid_core_setup_android | |
| veilid_core_setup_android(env, context); | |
| if output.is_null() { | |
| return output; | |
| } | |
| veilid_core_setup_android(env, context); |
When with_env().resolve::<ThrowRuntimeExAndDefault>() fails, jni 0.22 throws to Java and returns a null jstring. Bail out before calling veilid_core_setup_android or spawning the server with empty paths.
Author
|
Addresses the review feedback on Pushed in 977aab4. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Upgrades the Android
jnidependency from 0.21.1 to 0.22.4 and migrates the JNI bridge code to match the API expected by veilid-core v0.5.3.Without this change, Android builds fail when calling
veilid_core_setup_androidbecause veilid-core types its Android setup against jni 0.22 (EnvUnowned,JObject), while save-rust was still using jni 0.21 (JNIEnv).Problem
veilid-core v0.5.3depends onjni 0.22.xand exposes:save-rust pinned
jni = "0.21.1"for Android and passed incompatible types fromandroid_bridge.rs, producing:Solution
Dependency
[target.'cfg(target_os = "android")'.dependencies] jnito0.22.4inCargo.tomlsrc/android_bridge.rsEnvUnowned+with_env(|env| ...)+resolve::<ThrowRuntimeExAndDefault>()patternJNIEnvcalls (get_string,new_string,get_native_interface, etc.) withEnvAPIsveilid_core_setup_android(env, context)after JNI init/smoke-test and before spawning the server thread (Veilid must be ready before backend startup)jni_str!/jni_sig!for static Java method invocationsrc/jni_globals.rsGlobalRef→Global<JClass<'static>>init_jni/init_jni_innertake&mut EnvJavaVM::attach_current_threadupdated to callback style required by jni 0.22with_envhelper blockbuild-android.sh~/Library/Android/sdk, glob-based NDK version selection avoids ANSI-coloredlsoutput breaking path checks)../../Save-app-android/app/src/main/jniLibs)arm64-v8aaarch64-linux-androidarmeabi-v7aarmv7-linux-androideabix86_64x86_64-linux-androidjni 0.22 migration notes
JNIEnvin native methodsEnvUnownedentry +with_env→&mut Envenv.get_string()jstring.try_to_string(env)env.new_string()JString::from_str(env, ...)GlobalRefGlobal<T>attach_current_thread()→AttachGuardattach_current_thread(|env| ...)callbackTesting
cargo build --release(host)cargo ndk ... -t arm64-v8a -t armeabi-v7a build --release(Android)RUST_MIN_STACK=8388608 cargo test -- --test-threads=1— 13 passed, 0 failed, 2 ignored (~18 min)SnowbirdBridge.startServer/stopServer(not run in this PR)Follow-up
veilid-toolsstill transitively pullsjni 0.21.1; this is fine as long as save-rust and veilid-core share jni 0.22 at the integration boundary