6

I generate a .so file during my build and add it in the right place inside 'jnilibs' folder but I am facing an error stating "Cannot find the native function implementation with Unsatisfied Link Error"

// This is my .kt file

import abc.def.xyz

class MainActivity : Activity () {

public external fun MyNativeFunction() : Boolean

    override
    fun onCreate (pSavedInstance : Bundle?) 
    {
        super.onCreate (pSavedInstance)
    
        // Calling my Native function
    
        val check = MyNativeFunction ()
    }
}


// This is my .cpp file

extern "C" JNIEXPORT jboolean JNICALL
Java_abc_def_xyz_MainActivity_MyNativeFunction () noexcept

{

     // .... some code written here

    return true;
}

It's not able to find the function's implementation 'MyNativefunction'. Even the signature is correct but couldn't find where I am going wrong.

When I tried to extract the symbols from my generated .so file I was not able to see the this function inside the .so file. Can somebody tell me where I am going wrong?

Help would be appreciated.

Rohan Pande
  • 301
  • 1
  • 5
  • You left out the build system that creates the shared library from your cpp file, everything else looks fine. – Botje Aug 29 '23 at 08:15
  • I have multiple.cpp files of which we create multiple .a libraries and then we link it to a single .so file When I dumped the .a file I am able to see my native function symbol and it's present inside that But when I dump the .so file I am not able to see my native function inside that file Command used: "nm -gDC yourlibname.so" During linking libraries we use "target-link-library" of CMake – Rohan Pande Aug 29 '23 at 11:20
  • Your C++ function is missing the two arguments (`JNIEnv*, jobject`). Is that what your actual code looks like? – Michael Aug 29 '23 at 12:46
  • Voting to close as cannot reproduce, since there's no [mre] or information to go on. – Botje Aug 30 '23 at 07:47

0 Answers0