Repository navigation
Description
Android framework version
net10.0-android (Preview)
Affected platform version
.NET 10 RC 2
Description
Hello! We have identified an issue with how .NET loads native libraries, which we believe was introduced since .NET 10. From the release notes we believe "Use Android shared library loader for JNI libraries" (#10376) is the culprit.
Our understanding is that this commit will preload all libraries that define a JNI_OnLoad.
However, this changes the semantics of the code drastically. The example below illustrates this by loading a different library based on an external condition. Note that there are other cases as well but generally this change means that the libraries are always loaded, regardless of whether at that point they should be loaded, or whether the Java code loads them at all.
The change introduced by the aforementioned commit will break this mechanism. I have attached samples that is a stripped down version of a case where we ran into issues due to this change:
- An android SDK that provides a 'returnTrue()' method (implemented in native). If the correct native library is loaded, this method will return true.
- A sample android app, written in Java that shows returnTrue() does indeed return true.
- Bindings for the SDK + a Maui app that uses said bindings. A button can be pressed in the sample which will show that the wrong variant is loaded (as returnTrue() returns false).
Steps to Reproduce
Here are the aforementioned samples:
- Running 'JavaApp' will result in "True? true" being printed in the logcat.
- Running the 'MauiMainApp' sample will result in "True? false" being printed in the logcat.
This illustrates one of the ways preloading native libraries can result in unexpected behavior.
Did you find any workaround?
No response
Activity
Daedren commentedon Feb 5, 2026
I got around this with a really cursed method of extracting the .so files from the .aar and having them loaded on the side, but it is a pretty big problem around .NET Android, as I have a lot of external frameworks that are crashing or being loaded in the wrong manner, expecting both Android Context and MauiContext when they don't have it.
Doing this for everything is a gigantic pain.
Support for exempting native libraries from JNI preload (dotnet#10787)
Support for exempting native libraries from JNI preload (#10787)
Support for exempting native libraries from JNI preload (#10787)
[release/10.0.1xx] Support for exempting native libraries from JNI pr…