In JNI, when we use getfieldid/getstaticfieldid or getmethodid/getstaticmethodid and define jninativemethod, We need to indicate the type of the member variable, or the type of the input parameter or returned by the function. JNI abbreviated the field type, or the type of input parameter or return value of the function as char.
For member variables, you can simply use the abbreviation of Java type to indicate the type of member variables.
For example, "I" indicates that the member variable is of the int type.
"Ljava/lang/string;" indicates that the member variable is of the string type.
Example 1:
Jfieldid STR = (ENV)-> getfieldid (objectclass, "name", "ljava/lang/string ;");
Jfieldid ival = (ENV)-> getfieldid (objectclass, "serial", "I ");
For a member function, "(*) +" is used to indicate the input parameters of the function, the type of the input parameter, and the type of the return value. The character in "()" indicates the input parameter, and the subsequent character indicates the return value.
For example:
"() V" indicates void func ();
"(Ii) V" indicates void func (INT, INT );
"(Ljava/lang/string;) I". Int func (string, string)
Example 2:
Static jninativemethod gpowermanagerservicemethods [] = {
/* Name, signature, funcptr */
{"Nativeinit", "() V ",
(Void *) android_server_powermanagerservice_nativeinit },
{"Nativesetpowerstate", "(zz) V ",
(Void *) android_server_powermanagerservice_nativesetpowerstate },
{"Nativestartsurfaceflingeranimation", "(I) V ",
(Void *) android_server_powermanagerservice_nativestartsurfaceflingeranimation },
};
For abbreviated type, see the following table.Table
Java Type |
Symbol |
Boolean |
Z |
Byte |
B |
Char |
C |
Short |
S |
Int |
I |
Long |
L |
Float |
F |
Double |
D |
Void |
V |
Objects object |
It starts with "L" and ends with ";". It is a package and class name separated by "/" in the middle. For example: ljava/lang/string; For Nested classes, $ is used to represent nesting. For example, "(ljava/lang/string; landroid/OS/fileutils $ filestatus;) z" |
In addition, the abbreviation of the array type can be expressed in the abbreviated form of "[" and the corresponding type shown in table,
For example, [I indicates int []; [l/Java/lang/objects; indicates objects. The identifier of the reference type (except the basic type array) is ";"