- For calling the method of the C++ class in the JNI, the object of this class must be created already(if it's not a static method).
- You need to create the JNI wrappers only for the methods that can be called from the Java code.
Example:
C++ class:
class Controller
{
public:
void function1()
{
function2();
function3();
}
void function2(){}
void function3(){}
}
JNI methods:
JNIEXPORT void JNICALL Java_com_example_MainActivity_function1()
{
//getControllerInstance() must to return the already created
//instance of the class.
Controller* controller = getControllerInstance();
if(controller != nullptr)
controller->function1();
}
//If you want to call function2() method from Java.
JNIEXPORT void JNICALL Java_com_example_MainActivity_function2()
{
//getControllerInstance() must to return the already created
//instance of the class.
Controller* controller = getControllerInstance();
if(controller != nullptr)
controller->function2();
}
P.S. The above code is an example, it is not working code.