封装一下获取的函数名
///声明
jmethodID GetMethodID_(int line,
JNIEnv* jni,
jclass c,
const char* name,
const char* signature);
///获取函数名 ,传入行数,JNIEnv ,jclass ,函数名,函数签名.
jmethodID GetMethodID_(int line,JNIEnv* jni, jclass c,
const char* name,const char* signature) {
// jni 调用GetMethodID 获取函数名
jmethodID m = jni->GetMethodID(c, name, signature);
// 主要是检查是否有异常.
CHECK_EXCEPTION(jni) << "error during GetMethodID: " << name << ", "
<< signature << " line: " << line;
CHECK(m) << name << ", " << signature << " line: " << line;
return m;
}
///获取静态方法名 传入行数,JNIEnv ,jclass ,函数名,函数签名.
jmethodID GetStaticMethodID_(int line,
JNIEnv* jni,
jclass c,
const char* name,
const char* signature) {
jmethodID m = jni->GetStaticMethodID(c, name, signature);
CHECK_EXCEPTION(jni) << "error during GetStaticMethodID: " << name << ", "
<< signature << " line: " << line;
CHECK(m) << name << ", " << signature << " line: " << line;
return m;
}
///获取方法名 (最终使用这个函数)
#define _GET_METHOD_ID(_jni_, _c_, _name_, _signature_) \
GetMethodID_(__LINE__, _jni_, _c_, _name_, _signature_)
- 使用方式
jmethodID methodID =
_GET_METHOD_ID(env, jnicb.jcbCls, "OnRobotGetMultiDataRsp","(JLjava/lang/Object;)V");