Support
Kreate provides first-class support for integrating native C/C++ code into JVM projects via the Java Native Interface (JNI). The entire build pipeline — from project scaffolding to CMake compilation and runtime library resolution — is automated through a set of dedicated Gradle tasks.
JNI support was introduced in Kreate 1.1.0 and lives inside the platform.jvm.jni DSL block.
How It Works
When JNI is enabled, Kreate registers and wires up the following automatically:
kreate-jni-initialize— Scaffolds the native C++ project structure if it does not exist yetkreate-jni-build— Configures and builds the shared library via CMake (cmake -S . -B build→cmake --build)Compile hook —
kreate-jni-buildruns before every Kotlin compilation task so the native library is always up to dateRuntime path — All
TestandJavaExectasks receive-Djava.library.pathpointing to the CMake build output directory
Prerequisites
CMake 3.20 or later
A C++17 capable compiler (GCC, Clang, or MSVC)
JDK with JNI headers (included in any standard JDK installation)
Project Layout
A JNI-enabled module follows this directory convention:
The layout mirrors the C-Interop convention used for Rust projects, keeping native source structures consistent across both features.
Next Steps
Configuration: DSL reference and all available options
Project Scaffolding: How the
kreate-jni-initializetask worksBuild Pipeline: CMake build and runtime library path wiring