[NativeAOT] Set _UseNativeLibPrefix=true to fix UnsatisfiedLinkError on Android#10825
[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>
_UseNativeLibPrefix=true to fix UnsatisfiedLinkError on Android
MichalStrehovsky
left a comment
There was a problem hiding this comment.
When this underscored property was added, we very specifically did not want dotnet/android to set it: dotnet/runtime#118299 (comment)
|
I questioned if copilot's fix here was correct. Should we actually remove this line instead? I've been trying to get a maestro update that shows something broken, but it seems like the recent .NET SDK (vmr) builds are OK. |
is also setting the lib prefix. If this broke in 10.0 servicing, I wonder if some SDK change made these hacks stop working. It would have been much better to introduce a mechanism in dotnet/runtime than hacking around it like this. |
|
@copilot This PR is showing successful CI! 🎉 Status: ✅ All checks passing The NativeAOT UnsatisfiedLinkError fix appears to be working. Consider:
Action needed: Final validation and mark ready for review. |
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.