包括.h文件中到Java文件中的Andr​​oid使用JNI作为.h文件中的源文件夹? [英] include .h file into java file in android using jni as source folder of .h file?

查看:128
本文介绍了包括.h文件中到Java文件中的Andr​​oid使用JNI作为.h文件中的源文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  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;

我怎么可以添加.h文件中直接进入我的java文件。我使用NDK和.h文件我JNI folder.i里面要使用头文件的功能。我怎么可以直接使用功能,在java中的活动?请大家帮我

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

推荐答案

您不能直接调用C / C ++函数。的Java本机功能的C实现都有非常具体的参数设置:

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.

一个合理的方法是定义包括所有的原生功能的Java版本(如静态或实例方法)类,并通过该类调用它们。

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.

要生成从Java C头文件(当然,不是信号源,但.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

这篇关于包括.h文件中到Java文件中的Andr​​oid使用JNI作为.h文件中的源文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆