-
Notifications
You must be signed in to change notification settings - Fork 0
Getting Started
This tutorial starts with an existing Supernote React Native plugin and ends
with a Kotlin add(left, right) function running on a device. JNI and JSI use
the same example in their focused pages.
Python 3.9 or newer is required:
python3 -m pip install supernote-module-generatorConfirm the installed version:
supernote-module --versionSee Compatibility before installing Android or C/C++ tools.
Run the generator from the exact directory containing all of these markers:
PluginConfig.json
package.json
android/
android/settings.gradle # or settings.gradle.kts
The generator does not search parent directories. The official Supernote
template creates PluginConfig.json during its first packaging run. If a new
plugin does not have it, package the unmodified plugin once before continuing.
Check the plugin and Native toolchain without changing files:
supernote-module doctor --type nativeFrom the plugin root, start the guided interface:
supernote-moduleChoose Add module, then Native Module, and answer:
| Prompt | Answer | What it controls |
|---|---|---|
| Package name | local-math |
Folder, npm/Yarn dependency, and TypeScript import string |
| Description | leave empty | Optional local package metadata |
| JavaScript name | accept Math
|
Object registered with React Native |
| Android namespace | accept com.example.math
|
Kotlin/Java package and source path |
| Package version | accept 0.1.0
|
Local module version, not the plugin version |
| Install the local dependency now? | Yes | Runs npm or Yarn so autolinking can find the package |
The three identities—package name, JavaScript name, and Android namespace—must be unique among managed modules. Update cannot rename them or change the module type.
Edit this user-owned starter file:
local_modules/local-math/android/src/main/java/com/example/math/Example.kt
Replace its contents with:
package com.example.math
import com.example.math.nativemodule.annotation.SupernoteExport
class Example {
@SupernoteExport
fun add(left: Double, right: Double): Double = left + right
}The annotation tells the generator's Android build step to expose the method to JavaScript. Do not edit generated bridge or registration files.
Native value-returning exports are asynchronous from JavaScript, so use the
package's default import and await:
import React, {useState} from 'react';
import {Button, Text, View} from 'react-native';
import Math from 'local-math';
export default function App(): React.JSX.Element {
const [result, setResult] = useState('Not run');
async function runAdd() {
try {
const value = await Math.add(20, 22);
console.log('Math.add result:', value);
setResult(String(value));
} catch (error) {
console.error('Math.add failed:', error);
setResult(String(error));
}
}
return (
<View>
<Button title="Run native add" onPress={runAdd} />
<Text testID="math-result">{result}</Text>
</View>
);
}If generation used --skip-install, first link the local dependency with the
parent plugin's package manager:
npm installor:
yarn installPackage on macOS or Linux:
./buildPlugin.shPackage in Windows PowerShell:
.\buildPlugin.ps1For the official template's default name, the result is:
build/outputs/plugin.snplg
If PluginConfig.json uses another plugin name, use the filename actually
written to build/outputs/. The generator's --build option only runs the
parent Gradle :app:assembleDebug task; it does not replace the packaging
script or prove that a .snplg was produced.
Copy the package with Android Debug Bridge (ADB):
adb push "build/outputs/plugin.snplg" /storage/emulated/0/MyStyle/This transfers the file; it does not install it. On the Supernote, open Settings > Apps > Plugins > Add Plugin, select the package, and install it. The official parent-plugin workflow is also documented in Supernote's Your First Plugin guide.
Open the plugin and press Run native add. The UI should show 42.
Inspect JavaScript logs when it does not:
adb logcat -d -s ReactNativeJS:V '*:S'For generated Native bridge errors, include the module tag:
adb logcat -d -s SupernoteNativeMath:V ReactNativeJS:V '*:S'Kotlin/Java implementation under the module's android/src/main/java/ tree is
user-owned, except generated packages. Update replaces metadata, wrappers,
declarations, Gradle wiring, generated bridge code, and the generated README.
Remove deletes the entire package, including implementation source.
Commit before Update or Remove, then read Managing Modules.