Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unity: DllNotFoundException (Unity 2018.2; Android)

I have an Android native library (C++ code base) called:

libserverapp.so

And I cannot get the Android build to find it:

"DllNotFoundException: serverapp"

I am using an internal build system, but when I parse the output of the build process, I can see many calls of the form:

android-ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/windows/bin/arm-linux-androideabi-g++.exe -march=armv7-a

After building my Android app, I inspect the resulting APK (renaming to .zip and extracting), and can see my library file here:

lib/armeabi-v7a/libserverapp.so

I can confirm that "ARMv7" is the target architecture in the Android Player settings, and I access the library, in C#, via:

[DllImport("serverapp", CallingConvention = CallingConvention.Cdecl)]
private static extern void run_sim(StringBuilder matchInput, StringBuilder results, int randomSeed);

I have built a Windows DLL of the C++ code, to use in the Editor, and everything works great. However, when I move to Android, the .so cannot be found. The import settings for libserverapp.so are:

Platform: Android; CPU: ARMv7; Path: Assets/Plugins/Android/libserverapp.so; Type: Native

Given that the final APK includes the .so where I expect it to be (lib/armeabi-v7a/), I assume my Unity settings are correct? Also, I am not using IL2CPP for the Android build.

Finally, when I do an object dump of the library file (using arm-linux-androideabi-objdump.exe), the file format of the library file is "elf32-littlearm".

I feel that the issue here is simply finding the .so, not the functionality within it. Any ideas on what's going on here?

Thanks!

like image 421
hothead-brusnell Avatar asked May 17 '26 01:05

hothead-brusnell


1 Answers

I ended up solving the problem. I mentioned that was using an internal build system. Well, there seems to be a bug in it. I ported things over to official Android NDK makefiles, and then it "just worked". So in this case, the library could be found, but its contents weren't valid.

like image 140
hothead-brusnell Avatar answered May 19 '26 16:05

hothead-brusnell