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. (Unity - Manual: Native plug-ins)
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.
(Unity - Manual: Native plug-ins for Android)
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

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.

  1. Download the the zip file.
  2. Extract the AndroidNativePlugin.unitypackage file.
  3. Open the Unity Editor.
  4. Create a new Project.
  5. In the new project click Assets > Import Package & Custom Package.
  6. 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

  1. Open a command prompt and navigate to:
    \Assets\Plugins\Android\src
  2. Run the following command:

dk-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.
3. 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!

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!

I got an error saying dk-build.cmd is not recognized as an internal or external command. What is going wrong?