
Simplifies JNI interactions with concise syntax for calling methods and converting strings. Features a DSL for registering JNI methods, enhancing code readability and ease of use.
using this library:
implementation("io.github.landrynorris:jni-utils:0.0.1-alpha01")This library provides bindings to the JNI library on Android.
The primary motivator of this library is the syntax for calling a method on JNIEnvVar
env.pointed.pointed?.SetObjectField?.invoke(env, fieldId, value)This library allows you to write
env.setObjectField(fieldId, value)Or take for example, converting a Kotlin String to a jstring:
//Raw JNI library
memScoped {
env.pointed.pointed?.newString?.invoke(myString.wcstr.ptr, length)
}
//This library
myString.toJString(env)This library provides a DSL for registering JNI methods.
env.registerNatives {
clazz = env.findClass("io.github.landrynorris.sample.JniBridge".signature())
method("buttonClicked") {
signature = signature(::buttonClicked)
function = staticCFunction(::buttonClicked)
}
method("getText") {
signature = Signature(listOf(Long), String).toString()
function = staticCFunction(::getText)
}
}You must provide a clazz value in the DSL.
There are two ways of defining the signature:
using this library:
implementation("io.github.landrynorris:jni-utils:0.0.1-alpha01")This library provides bindings to the JNI library on Android.
The primary motivator of this library is the syntax for calling a method on JNIEnvVar
env.pointed.pointed?.SetObjectField?.invoke(env, fieldId, value)This library allows you to write
env.setObjectField(fieldId, value)Or take for example, converting a Kotlin String to a jstring:
//Raw JNI library
memScoped {
env.pointed.pointed?.newString?.invoke(myString.wcstr.ptr, length)
}
//This library
myString.toJString(env)This library provides a DSL for registering JNI methods.
env.registerNatives {
clazz = env.findClass("io.github.landrynorris.sample.JniBridge".signature())
method("buttonClicked") {
signature = signature(::buttonClicked)
function = staticCFunction(::buttonClicked)
}
method("getText") {
signature = Signature(listOf(Long), String).toString()
function = staticCFunction(::getText)
}
}You must provide a clazz value in the DSL.
There are two ways of defining the signature: