Calling another C ++ method from jni method in ndk

Firstly, I have a JNIEXPORT method that looks like this:

  JNIEXPORT void JNICALL Java_com_app_osap_Native_nativeProcessImage(JNIEnv *env, jobject thiz, jstring imagePath){
  // ...
   handle(data);
 }

Then I write another method in the same cpp file:

 void handle(int data[]){

 }

But I get this error when compiling the source code:

   'handle' was not declared in this scope

Please tell me what my problem is and how I can solve it.
Thanks in advance!

+3
source share
1 answer

Since you are not using headers, you need to declare a descriptor function before the JNI function. Or you can start using headers that will contain function declarations and then include them in your cpp file. How:

test.h:

void handle(int data[]);

test.cpp

#include test.h

Remember to add the title to your module in Android.mk:

include $(CLEAR_VARS)
LOCAL_MODULE := test
LOCAL_SRC_FILES := path/to/test.cpp
LOCAL_C_INCLUDES := path/to/test.h     #This is the header file you created
include $(BUILD_SHARED_LIBRARY)
+3
source

All Articles