Kotlin-JNI Help

⚙️ Kotlin JNI Extensions

Some of these extensions can be useful when not using the KSP generator and writing your own @CName-annotated functions.

Converting from JNI types to Kotlin types

Converting between JNI, Kotlin and back is easy:

import dev.datlag.nkommons.utils.* import dev.datlag.nkommons.JNIEnvVar import dev.datlag.nkommons.binding.jstring import dev.datlag.nkommons.binding.jintArray import dev.datlag.nkommons.binding.jbyteArray import kotlinx.cinterop.CPointer val jMessage: jstring = ... val kotlinString: String? = jMessage.toKString(env) require(jMessage == kotlinString?.toJString(env)) val jInts: jintArray = ... val kInts = jInts.toKIntArray(env) require(jInts == kInts?.toJIntArray(env)) val jBytes: jbyteArray = ... val kBytes: ByteArray? = jBytes.toKByteArray(env) require(jBytes == kBytes?.toJByteArray(env))

For a detailed list of functions, see the API Reference.

Last modified: 03 February 2026