-
Notifications
You must be signed in to change notification settings - Fork 537
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DllNotFoundException from Android emulator when calling into a native dll #8788
Comments
I just tested this on a physical android device. It works fine. Yay. More trivia: the emulator is running x86_64, and that's the ABI of the binary selected for inclusion in the app as well. |
Would be useful to know what's a typical approach diagnosing DllNotFoundException issues on Android. Supposedly it can happen when ABI is wrong or there is other problem with .so file. |
@AArnott I don't think Avalonia use much of our infrastructure, so this issue might probably be better filed in Avalonia, but can you provide the |
Looking at the Nuget package for Nerdbank.Zcash 0.2.68-beta it does not contain any andorid runtimes. only linux-x64? |
@dellis1972 you need to get the latest version from the nuget feed: https://github.com/AArnott/Avalonia-WithNativeDependency/blob/master/nuget.config#L7 |
ok. My guess then is its trying to use an x64 binary on an x86 or arm image on the emulator (as it works on a device). |
@AArnott also, a detailed exception message and stack trace would be necessary to see what might be going on. Try these commands to get the logcat output (including our runtime logging, not sure if it works with Avalonia): $ adb shell setprop debug.mono.log default,assembly,timing=bare,mono_log_level=debug,mono_log_mask=all
$ adb logcat -G 64M
$ adb logcat -c
# Start the app here, wait for it to crash, then wait 15s and
$ adb logcat -d > log.txt Attach the resulting |
Running the sample in an emulator, two issues stand out: @AArnott: First, the emulator doesn't like
i.e. "something is wrong" with
@grendello: The other issue is that commit 1aa0ea7 appears to have a bug, as my
Looks like this line (and others?) cannot be null: |
@jonpryor looks like that NREX is something really unexpected, will open a PR today. |
@grendello classic Avalonia mobile backends are built on top of .NET workloads (i.e. new Xamarin.Native), xamarin-android and xamarin-ios. |
Thanks folks. I've tried applying the workaround, but it requires the Here is my attempt: |
Context: #8788 (comment) Context: https://developer.android.com/reference/java/lang/StackTraceElement?hl=en#StackTraceElement(java.lang.String,%20java.lang.String,%20java.lang.String,%20int) `Java.Lang.StackTraceElement` constructor requires the `declaringClass` and `methodName` parameters to never be `null`. Pass the string `Unknown` whenever any of this information is missing from the managed stack frame. Additionally, the `lineNumber` parameter is now set to `-2` if we think a stack frame points to native code.
I got the NDK issues worked out and a successful build. However it still fails on the emulator. |
I'll try the logcat commands... if I can find where to enter them... |
It looks like it's still failing with the same missing external, despite having applied this workaround.
|
@AArnott: you can use # update as appropriate for your host OS
% $ANDROID_NDK_HOME/toolchains/llvm/prebuilt/darwin-x86_64/bin/llvm-nm -D \
…/bin/Debug/net8.0/runtimes/android-x64/native/libnerdbank_zcash_rust.so
…
U __extenddftf2 That won't tell you whether or not the binary is usable on the emulator -- running on the emulator is the best for that -- but it will be useful as part of the inner dev loop of "did this fix remove the use of this symbol?. |
Thanks. I ran that command on the binary before and after the popular workaround was applied. The before output included |
@AArnott the symbol missing after applying the workaround is the desired outcome, so we know the problem is fixed on that end. To make sure the correct library is used in the application, you might want to remove the application completely from the device and then perform a clean build of your app (after removing all the |
Thank you very much for those specific steps. In following them, I found some issues that may have led to the wrong binary being delivered to the emulator. Even after fixing those, the emulator crashed the first time, but then when debugging from VS, the crash disappeared, and then stayed away when not using the debugger. So I'm not sure what all was happening, but it appears to be resolved. Thank you! |
…8795) Context: #8788 (comment) Context: 1aa0ea7 The [`java.lang.StackTraceElement(String, String, String, int)`][0] constructor requires that the `declaringClass` and `methodName` parameters never be `null`. Failure to do so results in a `NullPointerException`: I DOTNET : JavaProxyThrowable: translation threw an exception: Java.Lang.NullPointerException: Declaring class is null I DOTNET : at Java.Interop.JniEnvironment.InstanceMethods.CallNonvirtualVoidMethod(JniObjectReference instance, JniObjectReference type, JniMethodInfo method, JniArgumentValue* args) I DOTNET : at Java.Interop.JniPeerMembers.JniInstanceMethods.FinishCreateInstance(String constructorSignature, IJavaPeerable self, JniArgumentValue* parameter s) I DOTNET : at Java.Lang.StackTraceElement..ctor(String declaringClass, String methodName, String fileName, Int32 lineNumber) I DOTNET : at Android.Runtime.JavaProxyThrowable.TranslateStackTrace() I DOTNET : at Android.Runtime.JavaProxyThrowable.Create(Exception innerException) I DOTNET : --- End of managed Java.Lang.NullPointerException stack trace --- I DOTNET : java.lang.NullPointerException: Declaring class is null I DOTNET : at java.util.Objects.requireNonNull(Objects.java:228) I DOTNET : at java.lang.StackTraceElement.<init>(StackTraceElement.java:71) I DOTNET : at crc6431345fe65afe8d98.AvaloniaMainActivity_1.n_onCreate(Native Method) Update `JavaProxyThrowable.TranslateStackTrace()` (1aa0ea7) so that if `StackFrame.GetMethod()` returns `null`, we fallback to: 1. Trying to extract class name and method name from [`StackFrame.ToString()`][1]: MainActivity.OnCreate() + 0x37 at offset 55 in file:line:column <filename unknown>:0:0 2. If (1) fails, pass `Unknown` for `declaringClass` and `methodName`. Additionally, the `lineNumber` parameter is now set to `-2` if we think a stack frame points to native code. [0]: https://developer.android.com/reference/java/lang/StackTraceElement#StackTraceElement(java.lang.String,%20java.lang.String,%20java.lang.String,%20int) [1]: https://github.com/xamarin/xamarin-android/pull/8758/files#r1504920023
…8795) Context: #8788 (comment) Context: 1aa0ea7 The [`java.lang.StackTraceElement(String, String, String, int)`][0] constructor requires that the `declaringClass` and `methodName` parameters never be `null`. Failure to do so results in a `NullPointerException`: I DOTNET : JavaProxyThrowable: translation threw an exception: Java.Lang.NullPointerException: Declaring class is null I DOTNET : at Java.Interop.JniEnvironment.InstanceMethods.CallNonvirtualVoidMethod(JniObjectReference instance, JniObjectReference type, JniMethodInfo method, JniArgumentValue* args) I DOTNET : at Java.Interop.JniPeerMembers.JniInstanceMethods.FinishCreateInstance(String constructorSignature, IJavaPeerable self, JniArgumentValue* parameter s) I DOTNET : at Java.Lang.StackTraceElement..ctor(String declaringClass, String methodName, String fileName, Int32 lineNumber) I DOTNET : at Android.Runtime.JavaProxyThrowable.TranslateStackTrace() I DOTNET : at Android.Runtime.JavaProxyThrowable.Create(Exception innerException) I DOTNET : --- End of managed Java.Lang.NullPointerException stack trace --- I DOTNET : java.lang.NullPointerException: Declaring class is null I DOTNET : at java.util.Objects.requireNonNull(Objects.java:228) I DOTNET : at java.lang.StackTraceElement.<init>(StackTraceElement.java:71) I DOTNET : at crc6431345fe65afe8d98.AvaloniaMainActivity_1.n_onCreate(Native Method) Update `JavaProxyThrowable.TranslateStackTrace()` (1aa0ea7) so that if `StackFrame.GetMethod()` returns `null`, we fallback to: 1. Trying to extract class name and method name from [`StackFrame.ToString()`][1]: MainActivity.OnCreate() + 0x37 at offset 55 in file:line:column <filename unknown>:0:0 2. If (1) fails, pass `Unknown` for `declaringClass` and `methodName`. Additionally, the `lineNumber` parameter is now set to `-2` if we think a stack frame points to native code. [0]: https://developer.android.com/reference/java/lang/StackTraceElement#StackTraceElement(java.lang.String,%20java.lang.String,%20java.lang.String,%20int) [1]: https://github.com/xamarin/xamarin-android/pull/8758/files#r1504920023
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
andlibgit2sharp
. Both of these carry aruntimes
folder. TheNerdbank.Zcash
package in particular carries aruntimes/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:
net7.0-android
tonet8.0-android
.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
The text was updated successfully, but these errors were encountered: