Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling another C++ method from jni method in ndk

First, I have a JNIEXPORT method look 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 compile 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!

like image 406
ductran Avatar asked Mar 14 '26 13:03

ductran


1 Answers

Since you don't use headers, you need to declare handle function before the JNI function. Or, you may start to use headers that will contain the declarations of the functions and then include it in your cpp file. Like:

test.h:

void handle(int data[]);

test.cpp

#include test.h

Don't forget to add the header to your module in your 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)
like image 196
eozgonul Avatar answered Mar 16 '26 01:03

eozgonul



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!