I am trying to use function overload when declaring JNI native functions.
The Java method is :
public native static void methodaaa(String type, int errorCode);
public native static void methodaaa(String type, byte[] byts);
Without overload, the code is shown as below:
JNIEXPORT void JNICALL Java_com_xxx_yyy_JavaCallCpp_methodaaa(JNIEnv* env, jobject thiz, jstring type, jint errorCode){}
And this works just fine.
Then I tried to add overload :
JNIEXPORT void JNICALL Java_com_xxx_yyy_JavaCallCpp_methodaaa(JNIEnv* env, jobject thiz, jstring type, jint errorCode){}
JNIEXPORT void JNICALL Java_com_xxx_yyy_JavaCallCpp_methodaaa(JNIEnv* env, jobject thiz, jstring type, jbyteArray buffer){}
And this give me the error :
conflicting types for Java_com_xxx_yyy_JavaCallCpp_methodaaa
Then I did some research and it seems like I need to add a "__" to the end of the functions that I want to overload and also append the arguments Name mangling.
So I tried:
JNIEXPORT void JNICALL Java_com_xxx_yyy_JavaCallCpp_methodaaa__Ljava_lang_String_I(JNIEnv* env, jobject thiz, jstring type, jint errorCode){}
JNIEXPORT void JNICALL Java_com_xxx_yyy_JavaCallCpp_methodaaa__Ljava_lang_String_B(JNIEnv* env, jobject thiz, jstring type, jbyteArray buffer){}
But it still not work, the error is :
No implementation found for native Lcom/xxx/yyy/JavaCallCpp;.methodaaa:(Ljava/lang/String;I)V
Is anybody know that how to write the JNICALL function name with a jstring as parameter or what I am doing wrong here?
Any advice will be appreciated, thanks :)
Update:
I found the link here :
http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/design.html
and then tried to modify my code :
JNIEXPORT void JNICALL Java_com_xxx_yyy_JavaCallCpp_methodaaa__Ljava_lang_String_2I(JNIEnv* env, jobject thiz, jstring type, jint errorCode){}
JNIEXPORT void JNICALL Java_com_xxx_yyy_JavaCallCpp_methodaaa__Ljava_lang_String_2B(JNIEnv* env, jobject thiz, jstring type, jbyteArray buffer){}
But, still I am getting the same error :
No implementation found for native Lcom/xxx/yyy/JavaCallCpp;.methodaaa:(Ljava/lang/String;I)V
Don't attempt to figure out JNI method signatures yourself. Use the output of javah. It is never wrong.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With