[java-runtime] Improve native library load diagnostics - #12313
Open
jonathanpeppers wants to merge 3 commits into
Open
[java-runtime] Improve native library load diagnostics#12313jonathanpeppers wants to merge 3 commits into
jonathanpeppers wants to merge 3 commits into
Conversation
Native library startup failures currently identify only that loading failed, which leaves crash reports without enough information to diagnose corrupt or incomplete installations. Route MonoVM, CoreCLR, and NativeAOT startup loads through a shared helper. When loading fails, report the requested library, supported ABIs, extracted file state, APK and split contents, and the original linker error. Suggest reinstallation when the library is absent from every inspected location. Add device coverage which deliberately removes the startup library from CoreCLR and NativeAOT packages and verifies the resulting diagnostic. Fixes #5149 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 8dffd648-59fe-4171-b126-1597a61cd438
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves startup diagnostics when the Android runtime fails to load required native libraries (MonoVM/CoreCLR/NativeAOT), making UnsatisfiedLinkError failures actionable by emitting a detailed logcat message (library name, ABI info, nativeLibraryDir state, APK/split contents, and original linker error). It also adds a device integration test that validates the improved diagnostic output by intentionally removing the startup library from built APKs.
Changes:
- Introduces a shared Java helper (
NativeLibraryHelper) to wrapSystem.loadLibrary()and generate rich diagnostics on failure. - Routes MonoVM/CoreCLR runtime library loads (and NativeAOT bootstrap load) through the shared helper.
- Adds an MSBuildDeviceIntegration test that removes the expected startup library from APKs and asserts the diagnostic appears in logcat.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/MSBuildDeviceIntegration/Tests/NativeLibraryLoadTests.cs | New device test validating the improved native-library load diagnostic in logcat. |
| src/Xamarin.Android.Build.Tasks/Resources/NativeAotRuntimeProvider.java | Ensures NativeAOT startup explicitly loads the native library via the shared helper path. |
| src/Xamarin.Android.Build.Tasks/Resources/JavaInteropRuntime.java | Replaces static library loading with an explicit loadLibrary(Context) that uses NativeLibraryHelper. |
| src/java-runtime/java/mono/android/NativeLibraryHelper.java | New shared helper that wraps native library loading and builds detailed failure diagnostics. |
| src/java-runtime/java/mono/android/MonoPackageManager.java | Routes MonoVM startup library loads through NativeLibraryHelper for improved error reporting. |
| src/java-runtime/java/mono/android/clr/MonoPackageManager.java | Routes CoreCLR startup library load through NativeLibraryHelper for improved error reporting. |
Suppressed comments (1)
src/java-runtime/java/mono/android/NativeLibraryHelper.java:124
- ❌ error:
appendApkDiagnosticsalso iteratesBuild.SUPPORTED_ABIS, which can throw on API < 21 and prevent the diagnostic from being generated. Use the same ABI fallback logic here as well so the error reporting works on older Android versions.
for (String abi : Build.SUPPORTED_ABIS) {
Follow the convention for newly added C# files. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 8dffd648-59fe-4171-b126-1597a61cd438
The NativeAOT application shared library already has the lib prefix in its FrameworkNativeLibrary identity. Match that filename so the failure test actually removes the library from the APK. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 8dffd648-59fe-4171-b126-1597a61cd438
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.
Pull Request
title and
description
should follow the
commit-messages.mdworkflow documentation, and in particular should include:Description
Native library startup failures currently provide too little information to diagnose corrupt, incomplete, or incorrectly split installations.
Route MonoVM, CoreCLR, and NativeAOT startup library loads through a shared helper. When loading fails, the resulting exception and logcat entry identify the requested library, supported ABIs, extracted native-library state, APK and split contents, and the original linker error. If the library is absent from all inspected locations, the message explains that reinstalling may repair a corrupt installation.
Add an MSBuildDeviceIntegration test which removes the real startup library from CoreCLR and NativeAOT APKs, verifies that it is absent from the package, and asserts the improved diagnostic in logcat.
Testing
src/java-runtime/java-runtime.csprojbuilds successfully for all runtime JAR variants.java_runtime_trimmable.jar.Fixes #5149