Skip to content

Add a Module

s edited this page Aug 1, 2026 · 3 revisions

Add a Module

Run the generator from the root of a Supernote plugin that already builds successfully.

1. Run from your plugin root

The generator requires:

PluginConfig.json
package.json
android/
android/settings.gradle       # or settings.gradle.kts

Check the generator and the backend you plan to use without changing files:

supernote-module doctor --type native

Use --type jni or --type jsi for a C/C++ backend.

2. Generate local-math

supernote-module

Choose Add module, then Native Module:

Prompt Example What it becomes
Package name local-math local_modules/local-math/, dependency name, and import string
Description leave empty Optional local package metadata
JavaScript name accept Math Object imported by JavaScript or TypeScript
Android namespace accept com.example.math Kotlin/Java package and generated path
Package version accept 0.1.0 Version of the local package
Install the local dependency now? Yes Links the package using your plugin's package manager

Note: The package name, JavaScript name, and Android namespace must be unique. Update cannot rename a module or change its backend.

Non-interactive:

supernote-module add local-math --type native --yes

3. Write the function

Edit:

local_modules/local-math/android/src/main/java/com/example/math/Example.kt
package com.example.math

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

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

Edit Example.kt; the other files in the package are generated. See Files the Generator Creates before customizing anything else.

4. Call the module

The generated package has one default export:

import Math from 'local-math';

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

Native and JNI value-returning exports use Promises. JSI exports return synchronously. Export Functions lists the supported signatures and call models.

5. Validate it

supernote-module validate local-math --build

Validate checks that the generated package is linked correctly. --build also compiles it through your plugin's Android project. Add --verbose when diagnosing a failed build.

If Add used --skip-install, run the normal npm install or yarn install command for your plugin before validating.

Then build and test your plugin as usual. Use the official Supernote documentation for that workflow.

Other backends

  • JNI Modules uses editable C/C++ and Promise-based calls.
  • JSI Modules uses editable C/C++ and synchronous calls, with additional host-runtime requirements.

Commit before Update or Remove, then read Managing Modules.

Clone this wiki locally