Skip to content

Export Functions

s edited this page Aug 1, 2026 · 3 revisions

Export Functions

The generator discovers marked Kotlin/Java methods or C++ functions and creates the bridge, registration, and TypeScript declaration needed by the existing plugin.

Generator names

Name Controls
Package name local_modules/ path, local dependency, import string, and metadata identity
JavaScript name Generated Native/JSI object and declarations
Android namespace Kotlin/Java package and generated source path
Export name Function property exposed on the generated object

For package local-math, the generator derives JavaScript name Math and namespace com.example.math. Explicit CLI options override those suggestions.

Kotlin and Java exports

Write .kt or .java below the generated implementation path:

local_modules/<package>/android/src/main/java/<namespace-path>/

Use the annotation generated for that module:

import com.example.math.nativemodule.annotation.SupernoteExport

class Example {
  @SupernoteExport
  fun add(left: Double, right: Double): Double = left + right

  @SupernoteExport(name = "greet")
  fun makeGreeting(name: String): String = "Hello, $name"
}

The processor accepts:

  • public instance methods on concrete public classes;
  • unique export names;
  • a public constructor taking ReactApplicationContext, Android Context, or no arguments, in that preference order.

It rejects suspend, inline, operator, static, generic, extension, and vararg exports.

Kotlin/Java boundary Generated TypeScript Call behavior
Boolean / boolean boolean Promise when returned
Double / double number Promise when returned
String string Promise when returned
Unit / void return void Fire-and-forget

Nullable values, collections, arrays, objects, integer-specific types, floats, callbacks, and arbitrary Android objects are not supported by this generator.

import Math from 'local-math';

const total = await Math.add(20, 22);
Math.setEnabled(true); // Unit/void export

C and C++ exports

Write JNI or JSI implementation below:

local_modules/<package>/android/src/main/cpp/

Place the marker immediately before a top-level C++ definition:

// @SupernoteExport
double add(double left, double right) {
  return left + right;
}

// @SupernoteExport(name = "greet")
std::string makeGreeting(std::string name) {
  return "Hello, " + name;
}

Supported boundary types are exactly bool, double, and UTF-8 std::string by value, plus void returns. noexcept is supported.

The generator rejects overloaded, namespaced, templated, static, inline, constexpr, extern "C", variadic, pointer, reference, default-argument, and decorated export signatures. Parameters and export names must be unique and explicitly named.

.cc, .cpp, and .cxx files may export. .c files compile as C23 and may provide internal helpers, but cannot contain export markers. Generated bindings and C++ sources compile as C++23.

JNI value returns use Promises:

import MathJni from 'local-math-jni';
const total = await MathJni.add(20, 22);

JSI returns and errors are synchronous:

import MathJsi from 'local-math-jsi';
const total = MathJsi.add(20, 22);

Ownership at the export boundary

The implementation files above are user-owned and preserved by Update. Generated annotations, processors, bridges, bindings, declarations, registration, Gradle, and CMake are generator-owned and replaceable. Remove deletes the complete generated module, including implementation source.

Clone this wiki locally