0

In a project, I cannot find the names of native functions in the .so libraries. That is, a native function must be called something like Java_com_package_ClassName_functionName(). I do find functionName in the .so libraries, but either without the Java_com_package_ClassName_ prefix, or wrapped into a mangled C++ name.

So:

  1. Does Qt (Necessitas) use a special naming convention?

  2. If yes, how it is done?

  3. If no, what is going on?

1

The naming conventions for JNI functions are given by the Dalvik VM, a library couldn't change them and expect them to work, i.e. be callable from the Java part of the application. But, the Java_package_function convention is only needed for functions that Java wants to call, it it not neccesary for a C/C++ function calling another one.

If you compile

jint Java_com_example_foo(JNIEnv*  env, jobject  this) { return bar(); }
int bar() { return 3; }

into a library, you can call Java_com_example_foo from java, and you won't be able to call bar from java, but nothing prevents Java_com_example_foo from calling bar.

So, there are 2 possibilities that come to mind:

  1. the Java part is nothing but a stub that calls a main function in one library, and all the rest is done in C or C++. This main function probably will be called Java_package_function, not main, but it's the only function that uses this naming convention.
  2. There's another wrapper library which provides the Java_package_function JNI API calls to the Java part, and calls the C/C++ functions which it imports from a different library. This library would probably be very small, so you might not have considered it interesting, and missed it in your previous analysis.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.