-
Notifications
You must be signed in to change notification settings - Fork 0
JNI Modules
The CLI calls this backend Native JNI Module. Use it when you want to call C or C++ from your plugin and a Promise-based JavaScript API is appropriate. The generator creates the Java Native Interface bridge, registration code, library loader, and CMake configuration.
Before creating a JNI module, check the C/C++ toolchain:
supernote-module doctor --type jniThen create the module using Add a Module, choosing Native JNI Module.
Edit the generated C/C++ folder:
local_modules/<package>/android/src/main/cpp/
Place the marker immediately before an ordinary top-level C++ definition:
// @SupernoteExport
double add(double left, double right) {
return left + right;
}Do not add JNI symbols, JNI_OnLoad, registration code, or CMake entries; the
generator creates them.
JNI value returns are asynchronous at the JavaScript boundary:
import NativeMath from 'native-math-jni';
const total = await NativeMath.add(20, 22);-
.cc,.cpp, and.cxxfiles may contain marked exports. -
.cfiles compile as C23 and may provide internal helpers, but cannot export. - C++ and generated bindings compile as C++23.
- Use
extern "C"guards in headers when C++ calls C helpers.
See Export Functions for supported types, signature rules, and string encoding.
supernote-module validate native-math-jni --buildAdd --verbose when diagnosing a failed build.
Update preserves the complete android/src/main/cpp/ directory. Remove deletes
it. See Managing Modules before either command.