Skip to content

JNI Modules

s edited this page Aug 1, 2026 · 4 revisions

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.

Check the toolchain

Before creating a JNI module, check the C/C++ toolchain:

supernote-module doctor --type jni

Then create the module using Add a Module, choosing Native JNI Module.

Write the C++ function

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.

Call it

JNI value returns are asynchronous at the JavaScript boundary:

import NativeMath from 'native-math-jni';

const total = await NativeMath.add(20, 22);

C and C++ files

  • .cc, .cpp, and .cxx files may contain marked exports.
  • .c files 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.

After changing exports

supernote-module validate native-math-jni --build

Add --verbose when diagnosing a failed build.

Update preserves the complete android/src/main/cpp/ directory. Remove deletes it. See Managing Modules before either command.

Clone this wiki locally