Skip to content

Fix Android native library loading and missing JNI export - #79

Merged
winnerspiros merged 7 commits into
masterfrom
android-native-fix-4658107465672926237
Feb 8, 2026
Merged

Fix Android native library loading and missing JNI export#79
winnerspiros merged 7 commits into
masterfrom
android-native-fix-4658107465672926237

Conversation

@google-labs-jules

Copy link
Copy Markdown

This PR fixes a crash on Android startup, especially in Release builds, by ensuring the native library is loaded via System.loadLibrary before any native methods are invoked. This guarantees that JNI_OnLoad is executed, initializing the global JavaVM pointer (g_vm) which is critical for VulkanRenderer and other native components that interact with the JNI environment.

Additionally, it adds a missing JNI export for nOboeStop to oboe_audio.cpp to align with the other exported methods and prevent potential linker errors if the method is accessed via JNI reflection or other mechanisms.

These changes address the user-reported crash on Android.


PR created automatically by Jules for task 4658107465672926237 started by @winnerspiros

…g JNI export.

- Add `global::Java.Lang.System.LoadLibrary("osu.Android.Native")` to `OsuGameActivity.OnCreate` to ensure `JNI_OnLoad` is called, which initializes `g_vm` required by `VulkanRenderer` and potentially internal Oboe JNI usage.
- Add `Java_osu_Android_Native_OboeAudio_nOboeStop` JNI export to `osu.Android/Native/oboe_audio.cpp` to prevent `UnsatisfiedLinkError` if the method is resolved via JNI.
@google-labs-jules

Copy link
Copy Markdown
Author

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

…g JNI export.

- Add `global::Java.Lang.System.LoadLibrary("osu.Android.Native")` to `OsuGameActivity.OnCreate` to ensure `JNI_OnLoad` is called, which initializes `g_vm` required by `VulkanRenderer` and potentially internal Oboe JNI usage.
- Add `Java_osu_Android_Native_OboeAudio_nOboeStop` JNI export to `osu.Android/Native/oboe_audio.cpp` to prevent `UnsatisfiedLinkError` if the method is resolved via JNI.
…enderer.

- Add `global::Java.Lang.System.LoadLibrary("osu.Android.Native")` to `OsuGameActivity.OnCreate` to ensure `JNI_OnLoad` is called, preventing immediate `UnsatisfiedLinkError` and initializing `g_vm`.
- Add `Java_osu_Android_Native_OboeAudio_nOboeStop` JNI export to `osu.Android/Native/oboe_audio.cpp` to prevent runtime crashes if `OboeAudio.Stop` is called.
- Add thread locking (`disposeLock`) to `osu.Android/Native/VulkanRenderer.cs` in `Render` and `Dispose` to prevent use-after-free race conditions.
…enderer.

- Add `global::Java.Lang.JavaSystem.LoadLibrary("osu.Android.Native")` to `OsuGameActivity.OnCreate` to ensure `JNI_OnLoad` is called, preventing immediate `UnsatisfiedLinkError` and initializing `g_vm`.
- Add `Java_osu_Android_Native_OboeAudio_nOboeStop` JNI export to `osu.Android/Native/oboe_audio.cpp` to prevent runtime crashes if `OboeAudio.Stop` is called.
- Add thread locking (`disposeLock`) to `osu.Android/Native/VulkanRenderer.cs` in `Render` and `Dispose` to prevent use-after-free race conditions.
@winnerspiros

Copy link
Copy Markdown
Owner

please check errors

@google-labs-jules

Copy link
Copy Markdown
Author

please check errors

Understood. I have investigated the CI failure and identified that System.LoadLibrary was causing a compilation error because System is ambiguous or missing in the Xamarin.Android context for Java.Lang. I have corrected it to global::Java.Lang.JavaSystem.LoadLibrary. I also verified the fix locally.

- Replace `Java.Lang.System.LoadLibrary` with `Java.Lang.JavaSystem.LoadLibrary` in `OsuGameActivity.cs` to resolve CS0234 error. Xamarin.Android maps `java.lang.System.loadLibrary` to `JavaSystem` to avoid conflict with the .NET `System` namespace.
- Fix flakiness in `TestSceneModPresetColumn.TestEditPresetMod` by checking `IsPresent` for the popover instead of just nullability. This ensures the popover is actually visible and part of the scene graph before interacting with it.
- (Previous commit) Fix Android startup crash by correctly loading native library with `JavaSystem.LoadLibrary`.
- Fix flakiness in `TestSceneTimingScreen.TestSelectionDismissedOnUndo` by using a null-conditional operator when checking `timingScreen.SelectedGroup.Value.Time`. This prevents potential NullReferenceExceptions during the wait loop if the selected group is transiently null, ensuring the test retries gracefully until the condition is met.
@winnerspiros
winnerspiros merged commit 6ede44b into master Feb 8, 2026
31 checks passed
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