include .h file into java file in android using jni as source folder of .h file?

泄露秘密 提交于 2020-01-05 04:40:13

问题


  void ProcedureParams_Initialize(ProcedureParams* pVal);
    flag ProcedureParams_IsConstraintValid(const ProcedureParams* val, int* pErrCode);
    flag ProcedureParams_XER_Encode(const ProcedureParams* val, ByteStream* pByteStrm, int* pErrCode, flag bCheckConstraints);
    flag ProcedureParams_XER_Decode(ProcedureParams* pVal, ByteStream* pByteStrm, int* pErrCode);
    flag ProcedureParams_BER_Encode(const ProcedureParams* val, ByteStream* pByteStrm, int* pErrCode, flag bCheckConstraints);
    flag ProcedureParams_BER_Decode(ProcedureParams* pVal, ByteStream* pByteStrm, int* pErrCode);

typedef struct {
    GeneralEvthParams g_params;
    DataParams d_params;
} EvtHandlerParams;

how i can add .h file directly into my .java file. i'm using NDk and .h file inside my jni folder.i want to use the functions of header file . how i can directly use functions in java activity? please help me


回答1:


You cannot invoke the C/C++ functions directly. The C implementations of Java native functions all have a very specific set of parameters:

  JNIEXPORT jint JNICALL Java_com_mycompany_MyClassName_myfunc
    (JNIEnv * env, jobject obj, jint code) {
     ...
  }

So you will have to create wrapper functions.

A reasonable approach is to define a class including the Java versions of all your native functions (as either static or instance methods), and invoke them via that class.

To generate C headers from the Java (well, not source but the .class files), you can do:

cd bin/classes
javah com.mycompany.MyClassName com.mycompany.AnotherClassName


来源:https://stackoverflow.com/questions/22040660/include-h-file-into-java-file-in-android-using-jni-as-source-folder-of-h-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!