- Home /
NativePlugin c++ Android sample and self build pcl not loading,Native Plugins c++ "dll not found"
Hello unity-community,
i got some trouble with native Plugins. I compiled the pointCloudLib (PCL) into a static and dynamic lib. Both of them can't be found when calling them like your documentation descripes. (https://docs.unity3d.com/Manual/NativePlugins.html) Tryed import with:
[DllImport("libnative.so")]
private static extern float add(float x, float y);
[DllImport("native")]
private static extern float add(float x, float y);
With both i get same result:
System DllNotFoundException: libnative.so / native
at (wrapper managed-to-native) CallNativeCode: add(single,single)
at CallNativeCode._callAdd (Single x, Single y) [0x00000] in <filename unkown>:0
at Thesis.Scripts.AppController.Update () [0x00000] in <filename unkown>:0
File location of Plugins are \Assets\Plugins\Android
Even your sample AndroidNativePlugin-file doesn't work for me. (https://docs.unity3d.com/Manual/AndroidNativePlugins.html) Maybe I'm doing something wrong. I tryed with followed Unity-versions:
2018.3.0f2
2018.2.15f
2017.4.17f1
Thanks in edvance for helping me
Yours sincerely
Stefan
Answer by madleen_unity · Feb 27, 2019 at 10:53 AM
Hi,
The issue seems to be that the .so file in the package is out of date.
Here are the proposed steps to recompile the .so file:
You will need to use the NDK for this but it is a requirement for native plugin use so you should already have this installed.
Follow the steps as described in the 'Native plug-in Sample' to set up the test project.
Download the the zip file.
Extract the AndroidNativePlugin.unitypackage file.
Open the Unity Editor.
Create a new Project.
In the new project click Assets > Import Package & Custom Package.
In the Import Package file dialog, navigate to the location in which you extracted the file and select it.
Next you will need to use the NDK build command to rebuild the libnative.so
Open a command prompt and navigate to: \Assets\Plugins\Android\src
Run the following command: \ndk-build.cmd NDK_PROJECT_PATH=. NDK_APPLICATION_MK=Application.mk This may warn you that the requested android NDK version is not supported but it will just use the minimum supported version for your installed NDK. This will produce a new libnative.so file.
Copy the new libnative.so file from: \Assets\Plugins\Android\src\libs\armeabi to \Assets\Plugins\Android
This will replace the old libnative.so file which is already in that location and this got rid of the exception.
I have notified the developers to update the Manual with a recompiled .so file, but I hope until then the steps mentioned above will help you out!
Answer by Aw0k3n · Mar 05, 2019 at 05:10 PM
Hello and thanks you for your answer,
I followed your instructions. Had to make a change in the Application.mk File
ABI := armeabi
to
ABI := armeabi-v7a
After this change and running your command i got a new .so file. Now its working perfectly fine! Thanks again!