Android将“.c”后缀名改为“.cpp”时java调用native失败及“error: base operand of '->' has non-poin
---------------------------------------华丽的分割线-----------------------------------------
现象:“.c”后缀名改为“.cpp”时java调用native失败?。
解决:?加入“ extern "C" ”。??
?
现象:“error: base operand of '->' has non-pointer type '_JNIEnv'”错误。???
解决:?将“(*env)->NewStringUTF(env, "HelloWorld from JNI !");”改为“env->NewStringUTF("HelloWorld from JNI !")”。
?
例子:
?
#include <stdio.h>#include <string.h>#include <android/log.h>#include <jni.h>#ifdef __cplusplusextern "C"{#endifjint Java_com_duicky_MainActivity_add(JNIEnv* env, jobject thiz, jint x, jint y){//该方法为打印的方法__android_log_print(ANDROID_LOG_INFO, "JNIMsg", "Get Param: x=%d y=%d ", x, y);int iRet = x + y;return iRet;}jstring Java_com_duicky_MainActivity_getString(JNIEnv* env, jobject thiz){jstring strRet = env->NewStringUTF("HelloWorld from JNI !");return strRet;}#ifdef __cplusplus}#endif
?