-
Notifications
You must be signed in to change notification settings - Fork 0
Kotlin and Java Modules
The CLI calls this backend Native Module. Use it for Kotlin/Java libraries and Android APIs. Value-returning exports are Promise-based in JavaScript.
Interactive:
supernote-moduleChoose Add module and Native Module.
Repeatable command:
supernote-module add local-math --type native --yesFor local-math, the default identities are JavaScript name Math and Android
namespace com.example.math.
The generated starter file is:
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
@SupernoteExport(name = "greet")
fun makeGreeting(name: String): String = "Hello, $name"
}The annotation import is specific to the generated Android namespace. Java sources use the same annotation.
import Math from 'local-math';
const total = await Math.add(20, 22);
const message = await Math.greet('Supernote');Use await for Boolean, Double, or String returns. A Unit/void export
is fire-and-forget:
@SupernoteExport
fun setEnabled(enabled: Boolean) {
// Apply the setting.
}Math.setEnabled(true);An exported concrete public class needs one of these public constructors, used in this preference order:
-
ReactApplicationContext; -
android.content.Context; - no arguments.
Activity injection and arbitrary constructor parameters are not supported.
supernote-module validate local-math --build --verbose
./buildPlugin.shOn Windows PowerShell, use \.\buildPlugin.ps1 for packaging. Build after
changing exports because the Android/KSP step regenerates declarations.
Your Kotlin/Java implementation below android/src/main/java/ is preserved by
Update, except generated packages. Do not edit the generated annotation,
processor, bridge, registration, Gradle, wrapper, or declaration files. Remove
deletes the entire module.
See Exports and JavaScript API for the complete signature rules and Managing Modules before Update/Remove.