[NativeAOT] Set _UseNativeLibPrefix=true to fix UnsatisfiedLinkError on Android#10825
Draft
[NativeAOT] Set _UseNativeLibPrefix=true to fix UnsatisfiedLinkError on Android#10825
_UseNativeLibPrefix=true to fix UnsatisfiedLinkError on Android#10825Conversation
Set _UseNativeLibPrefix=true so the NativeAOT SDK produces the native binary with the "lib" prefix from the start (e.g. libMyApp.so). Android requires native libraries to have this prefix. Also update soname to use $(NativeBinaryPrefix) for consistency and make _AndroidFixNativeLibraryFileName handle both cases (with and without NativeBinaryPrefix) for backward compatibility. Fixes #10822 Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix NativeAOT Android app crash with UnsatisfiedLinkError
[NativeAOT] Set Feb 17, 2026
_UseNativeLibPrefix=true to fix UnsatisfiedLinkError on Android
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.
NativeAOT Android apps crash on startup with
UnsatisfiedLinkErroratSystem.loadLibrarybecause the native binary may not have the requiredlibprefix in the APK.dotnet/runtime#118299 changed
ComputeLinkedFilesToPublishto derive the native binary path from$(NativeBinary)(which includes$(NativeBinaryPrefix)) instead of%(IntermediateAssembly.Filename), and introduced opt-in_UseNativeLibPrefixto control thelibprefix. Android'sSystem.loadLibrary("X")requireslibX.so— we should opt in.Changes in
Microsoft.Android.Sdk.NativeAOT.targets:_UseNativeLibPrefix=trueso the NativeAOT SDK produceslibTargetName.sonatively, matching Android's library naming requirement$(NativeBinaryPrefix)in soname instead of hardcodedlibprefix, keeping soname consistent with the actual binary filename_AndroidFixNativeLibraryFileName— addlibprefix when missing (backward compat), and explicitly setArchiveFileNamewhen the runtime already added it via$(NativeBinaryPrefix)Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.