Skip to content

DllNotFoundException from Android emulator when calling into a native dll #8788

@AArnott

Description

@AArnott

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 AArnott/Avalonia-WithNativeDependency#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

Metadata

Metadata

Assignees

Labels

need-attentionA xamarin-android contributor needs to review

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions