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:

  1. Create a new Avalonia Android app. Bump its target framework from net7.0-android to net8.0-android.
  2. Add a PackageReference to Nerdbank.Zcash
  3. 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

Most upvoted comments

@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.