registerNatives
fun JClass.registerNatives(methods: CArrayPointer<JniNativeMethod>, methodsCount: Int)(source)
Registers native methods with the class specified by the receiver. The methods parameter specifies a list of triples that contain the names, signatures and function pointers of the native methods.
The function pointers nominally must have the following signature:
(env: JniEnv, objectOrClass: JObject, ...) -> JBoolean|Byte|JChar|Short|Int|Long|Float|Double|JObject|UnitBe aware that registerNatives can change the documented behavior of the JVM (including cryptographic algorithms, correctness, security, type safety), by changing the native code to be executed for a given native Java method. Therefore, use applications that have native libraries utilizing the registerNatives function with caution.
Throws
if a specified method cannot be found or if the method is not native.
inline fun JClass.registerNatives(count: Int, block: JNINativeMethodRegistry.() -> Unit)(source)
Registers native methods with the class specified by the clazz argument.
The function pointers nominally must have the following signature:
(env: JniEnv, objectOrClass: JObject, ...) -> JBoolean|Byte|JChar|Short|Int|Long|Float|Double|JObject|UnitExample:
clazz.registerNatives(1) {
register("myGetStringBytes".utf8, "(Ljava/lang/String;II[B)V".utf8, staticCFunction { env: JniEnv, obj: JObject, jstr: JString, offset: Int, len: Int, buf: JByteArray ->
...
})
}Be aware that registerNatives can change the documented behavior of the JVM (including cryptographic algorithms, correctness, security, type safety), by changing the native code to be executed for a given native Java method. Therefore, use applications that have native libraries utilizing the registerNatives function with caution.
Throws
if a specified method cannot be found or if the method is not native.