Skip to content

Kotlin and Java Modules

s edited this page Aug 1, 2026 · 4 revisions

Kotlin and Java Modules

The CLI calls this backend Native Module. Use it for Android APIs and Kotlin or Java libraries. Value-returning functions use Promises in JavaScript.

Create the module using Add a Module, choosing Native Module.

File to edit

Write .kt or .java files below:

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

The starter implementation is Example.kt.

Kotlin example

package com.example.calculator

import com.example.calculator.nativemodule.annotation.SupernoteExport

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

Java example

If you prefer Java, replace the starter with Example.java:

package com.example.calculator;

import com.example.calculator.nativemodule.annotation.SupernoteExport;

public class Example {
  public Example() {}

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

The annotation import changes with the Android namespace selected for the module.

Call it from JavaScript

import Calculator from 'local-calculator';

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

Use await for Boolean/boolean, Double/double, or String returns. Functions returning Unit or void are called without await:

@SupernoteExport
fun setEnabled(enabled: Boolean) {
  // Apply the setting.
}
Calculator.setEnabled(true);

Constructor rules

An exported concrete public class needs one of these public constructors, used in this preference order:

  1. ReactApplicationContext;
  2. android.content.Context;
  3. no arguments.

Activity injection and arbitrary constructor parameters are not supported.

After changing exports

supernote-module validate local-calculator --build

The Android/KSP build regenerates declarations and the bridge. Add --verbose when diagnosing a failed build.

Update preserves your Kotlin and Java implementation. See Files the Generator Creates for the files Update may replace, and Export Functions for all supported signatures.

Clone this wiki locally