-
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 implementation belongs in C or C++ and a Promise-based JavaScript call is appropriate. The generator owns the Kotlin/Java Native Interface (JNI) bridge and registration.
supernote-module add local-math-jni --type jni --yesThe derived JavaScript name is MathJni and the Android namespace is
com.example.math_jni.
Check the C/C++ toolchain first when needed:
supernote-module doctor --type jniEdit the user-owned C/C++ tree:
local_modules/local-math-jni/android/src/main/cpp/
For example, edit math.cpp:
// @SupernoteExport
double add(double left, double right) {
return left + right;
}The marker must be immediately before an ordinary top-level C++ definition.
Do not write a JNI function, JNI_OnLoad, native registration, a loader, or
generated CMake entries.
JNI value returns are asynchronous at the JavaScript boundary:
import MathJni from 'local-math-jni';
const total = await MathJni.add(20, 22);Generated JNI transports strings as UTF-8 byte arrays instead of JNI modified UTF-8.
-
.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.
Supported boundary values are bool, double, and UTF-8 std::string by
value, plus void returns. See Exports and JavaScript API
for restrictions.
supernote-module validate local-math-jni --build --verbose
./buildPlugin.shThen reinstall the resulting .snplg and inspect both bridge and JavaScript
logs if a call fails:
adb logcat -d -s SupernoteNativeMathJni:V ReactNativeJS:V '*:S'Update preserves the complete android/src/main/cpp/ tree, including your
choice to delete starter files. It replaces metadata, wrappers, declarations,
Gradle/CMake, generated Kotlin/C++, loading, registration, and the generated
README. Remove deletes everything in the module, including the C/C++ tree.