Android JNINativeMethod

The content from http://arm9.org.ru/redirect.php?tid=356&goto=lastpost

Android uses a structure “JNINativeMethod” to describe the JNI function as follows:

typedef struct {
    const char* name;
    const char* signature;
    void*       fnPtr;
} JNINativeMethod;

name: name of function in Java
signature: used to describe the parameters and return values of function
fnPtr: function pointer that point to C function。

Take some examples for second parameter:
“()V”
“(II)V”
“(Ljava/lang/String;Ljava/lang/String;)V”

“()” stands for the parameter, the later represents the return value.
Take “()V” as an example. It means “void Func();”

“(II)V” means “void Func(int, int)”;

Mapping table as below:


character     C type         Java type

V                  void             void
Z                  jboolean       boolean
I                   jint               int
J                   jlong            long
D                  jdouble        double
F                  jfloat            float
B                 jbyte             byte
C                 jchar             char
S                 jshort           short

“array” denoted two characters as below:

[I       jintArray        int[]
[F       jfloatArray      float[]
[B       jbyteArray       byte[]
[C       jcharArray       char[]
[S       jshortArray      short[]
[D       jdoubleArray     double[]
[J       jlongArray       long[]
[Z       jbooleanArray    boolean[]

The above types discussed are standard. If the parameter is “class” type, start with “L” and end with “;”. Using “/” to separate package name and class name. And the parameter mapping to C is “object” except for String class. Its mapping is jstring.

Ljava/lang/String;     String         jstring
Ljava/net/Socket;      Socket         jobject

If Java function is placed in the embedded class, Using “$” as separated character.

i.e. “(Ljava/lang/String;Landroid/os/FileUtils$FileStatus;)Z”

Leave a Reply

Your email address will not be published. Required fields are marked *