android: DllNotFoundException from Android emulator when calling into a native dll
Android application type
.NET Android (net7.0-android, net8.0-android, etc.)
Affected platform version
VS 2022 Update 9, net8.0-android
Description
When my new Avalonia Android project consumes a native library, at runtime it throws DllNotFoundException.
These native libraries come by way of NuGet. I’ve tried Nerdbank.Zcash and libgit2sharp. Both of these carry a runtimes folder. The Nerdbank.Zcash package in particular carries a runtimes/android-x64/native/libnerdbank_zcash_rust.so file.
I can see that the file is included in the apk. But the android emulator still fails.
More details and diagnostic efforts are described in https://github.com/AArnott/Avalonia-WithNativeDependency/issues/1
Steps to Reproduce
A minimal repro is available here: https://github.com/AArnott/Avalonia-WithNativeDependency Be sure to switch the solution platform to x64, since in AnyCPU, no native binary is included in the deployed app.
In effect:
- Create a new Avalonia Android app. Bump its target framework from
net7.0-androidtonet8.0-android. - Add a PackageReference to Nerdbank.Zcash
- Add code that exercises the native library, for example these two lines.
Run the app in the android emulator. (I haven’t tried a real android device).
Did you find any workaround?
Nothing yet.
Relevant log output
No response
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 19 (17 by maintainers)
Commits related to this issue
- Prevent NREX when instantiating Java.Lang.StackTraceElement Context: https://github.com/xamarin/xamarin-android/issues/8788#issuecomment-1980765624 Context: https://developer.android.com/reference/ja... — committed to dotnet/android by grendello 3 years ago
- [Mono.Android] Prevent NullPointerException in TranslateStackTrace (#8795) Context: https://github.com/xamarin/xamarin-android/issues/8788#issuecomment-1980765624 Context: 1aa0ea7a8aef616d00e8467aa9... — committed to dotnet/android by grendello 3 years ago
- [Mono.Android] Prevent NullPointerException in TranslateStackTrace (#8795) Context: https://github.com/xamarin/xamarin-android/issues/8788#issuecomment-1980765624 Context: 1aa0ea7a8aef616d00e8467aa9... — committed to dotnet/android by grendello 3 years ago
@grendello classic Avalonia mobile backends are built on top of .NET workloads (i.e. new Xamarin.Native), xamarin-android and xamarin-ios.
@jonpryor looks like that NREX is something really unexpected, will open a PR today.
@dellis1972 you need to get the latest version from the nuget feed: https://github.com/AArnott/Avalonia-WithNativeDependency/blob/master/nuget.config#L7