Call method from c++ plugin in thread

Hi,

after Googling around for a while I thought maybe someone here knows an answer to my issue. I have a c++ lib compiled as .so-file for android. Calling these c++ methods from unity is no problem within the main thread and it’s all working. Due to performance issues I want to put the c++ calls in a seperate background worker.

Now if I create a background worker and start the calls I get an error message in log cat while running on an android device:

Unable to find 'myCustomLibName'
(Filename: PlatformDependent/AndroidPlayer/DVMCalls.cpp Line: 168)

This is my background worker test:

[DllImport("myCustomLibName")]
private static extern void libMethod();

void Start()
{
    BackgroundWorker bw = new BackgroundWorker();
    bw.DoWork += new DoWorkEventHandler(bw_DoWork);

    bw.RunWorkerAsync();
}


private void bw_DoWork(object sender, DoWorkEventArgs e)
{
    System.Threading.Thread.Sleep(500);

    libMethod(); //<-- c++ method call 
}

Would be great if anybody could help me with this issue.

edit:

  • I’m using Untiy Pro and Android Pro btw

  • changed ‘libName’ to ‘myCustomLibName’ to avoid confusion

You mention that it’s working from the main thread, however from all i know (and from the docs here: Unity - Manual: Create and use plug-ins in Android)

It is said that the attribute should declare the library WITHOUT the “lib” prefix.

e.g, you would have to define your extern method like this:

[DllImport("Name")]
private static extern void libMethod();

Where libName.so is the filename that you place under Plugins/Android