Signed over-the-air updates for NativeScript: native boot selection, runtime compatibility checks and offline crash rollback.
Documentation · Roadmap (#1) · Support matrix · Milestones
import { updates } from '@getcortexlabs/otto-nativescript';
// Call once the first usable screen has mounted (never gate on network reachability).
export function onAppUsable() {
updates.markReady();
void updates.checkAndStage().catch((error) => {
console.warn('[OTA] Background update skipped:', error);
});
}Shipping JavaScript over the air in NativeScript breaks in three specific ways when treated like a file copy:
- Broken updates cannot recover themselves. If a new bundle throws on its first import, JavaScript recovery code never executes. Bundle selection and launch-attempt accounting have to run in native code before V8 boots.
- Asset paths and runtime extraction collide. On Android,
@nativescript/core'sknownFolders.currentApp()resolves tofiles/app, whileRuntimeHelperwipesfiles/appwhen the APK changes. Overwritingfiles/appin place destroys the embedded fallback; loading JS from another folder without aligningfiles/appserves stale~/...assets alongside new code. - "I only edited TypeScript" is not a compatibility guarantee. NativeScript generates platform metadata and native bindings during the binary build. A new JS bundle that calls a native API or registers a native subclass absent from the installed binary fails at runtime.
Otto addresses those directly. Minimal native bootstrappers on iOS and Android select the active bundle before V8 starts, without forking @nativescript/ios or @nativescript/android and without hand-editing generated platforms/ folders. Bundles are staged atomically as complete, Ed25519-signed packages verified against a per-platform runtime contract, activated on the next full process launch, and rolled back offline if startup fails before markReady().
The SDK stays independent of any specific UI library or hosting backend. It speaks a server-agnostic HTTP contract tested locally via a fixture server; Otto provides the hosted console, app-scoped publishing, channels and delivery telemetry. The SDK also works with self-hosted Otto or any compatible server.
Current status (M0–M3 + #15, #16, #17 verified). All v0.1 milestones plus NativeScript 9.1 @nativescript/vite production support (#15), Android V8 snapshot compatibility rules & codeCache verification (#16), and content-addressed file reuse across releases (#17) are delivered and verified 8/8 on both Webpack 5 (fixtures/vue-mavis-app, NativeScript-Vue 3 + Mavis + Jolt) and Vite 8 / Rolldown (fixtures/vite-app, native ESM + require(esm) + ns:util + Web Worker) running on iOS 26.2 Simulator (@nativescript/ios 9.1.1) and a physical Xiaomi M2103K19PG Android 16 / API 36 device (@nativescript/android 9.1.3, signed R8 minifyEnabled true APK). Full operational docs and interactive Jolt Web labs live at otto.getcortexlabs.com/docs. Follow roadmap & ecosystem integrations in #1.
Both platforms keep the store-shipped embedded bundle immutable, preserve the last confirmed working OTA release alongside it, and persist state atomically in state.json before starting V8.
| Platform | Hook point | Storage root | Bundle switching |
|---|---|---|---|
iOS (@nativescript/ios 9.1.1) |
NS_SWIFTUI_BOOT = 1 in plugin build.xcconfig suppresses internal/main.m; CortexOtaMain.m calls CortexOtaBootstrapper before NativeScript.runMainApplication. |
Library/Application Support/com.getcortexlabs.ota (NSURLIsExcludedFromBackupKey) |
Passes the selected release directory (or Bundle.main.resourcePath) as Config.BaseDir. |
Android (@nativescript/android 9.1.3) |
OtaAndroidPlugin registered via com.tns.internal.Plugin meta-data, invoked by RuntimeHelper.initRuntime before asset extraction and V8 init. |
context.getFilesDir()/ota (private internal storage) |
Extracts APK assets/app into files/ota/embedded/app, keeps OTA releases under files/ota/releases/<id>/app, and switches files/app via atomic POSIX symlink (Os.symlink + Os.rename). |
Because Config.BaseDir on iOS and the files/app symlink on Android align the runtime root with knownFolders.currentApp(), entry modules (.mjs/.js), dynamic Webpack/Rollup chunks, require(esm) targets, ns: built-ins, web workers, V8 codeCache .cache files and ~/... assets all resolve cleanly from the same active release directory without mixing files across versions.
During staging, unchanged files matching the manifest's exact sha256 and byte size are reused locally from the active release or embedded bundle (APFS copy-on-write on iOS; byte copy on Android) before falling back to HTTP download, cutting JS-only update bandwidth by >99% while preserving full per-release isolation and full inventory verification.
cold launch (native, before V8)
├── binary build or runtimeContract changed?
│ └── reset OTA pointers -> boot immutable embedded bundle
├── pendingLaunch already set from a prior unconfirmed boot?
│ ├── attempts >= maxLaunchAttempts -> blocklist releaseId,
│ │ record lastRecovery -> boot lastConfirmed OTA (or embedded)
│ └── attempts < maxLaunchAttempts -> increment attempts -> retry candidate
├── stagedReleaseId ready and valid on disk?
│ └── set pendingLaunch (attempts = 1) -> boot candidate
├── confirmedReleaseId valid on disk?
│ └── boot confirmed OTA release
└── fallback -> boot immutable embedded bundle
Calling markReady() after the first usable screen mounts promotes a pending candidate to confirmedReleaseId and clears pendingLaunch atomically. Neither markReady() nor recovery requires network access.
Explicit limits. Absence of markReady() cannot tell a crash apart from a user force-closing the app mid-startup, so retry counts stay conservative. Rolling back JavaScript also cannot revert local SQLite schema changes or persisted preferences; OTA releases must keep local storage changes backward-compatible with the previous release.
Before a downloaded bundle can be staged (#7), the client checks three separate properties:
- Integrity: every file in the manifest inventory is present, matches its exact byte size and SHA-256 digest, and contains no path traversal, symlinks or extra files.
- Authenticity: the canonical manifest and server directive signatures verify under Ed25519 against public keys embedded in the binary (indexed by
keyIdfor key rotation). Private keys never enter the app. - Compatibility:
appId,platform,targetBuild,runtimeContractandprotocolVersionmatch the installed binary.
The wire protocol in packages/otto-protocol separates three concepts:
- Release manifest — an immutable, signed description of every file in a bundle (
protocolVersion,appId,platform,targetBuild,runtimeContract,releaseId,entry,createdAt,files). - Update directive — a signed server decision (
updateorrollback_to_embedded) carrying a monotonicdirectiveSeq. Rolling back fromota-105(directiveSeq: 12) toota-104issues a newer directive (directiveSeq: 13) pointing atota-104, so rollbacks never require accepting replayed directives. - Local activation — the on-device
BootStatepersisted instate.json.
Signatures cover domain-separated canonical JSON (ota-nativescript:manifest:v1\n and ota-nativescript:directive:v1\n) with RFC 8785 lexicographical key sorting. Cross-platform golden Ed25519 vectors live in packages/otto-protocol/test/vectors.json.
import {
assertDirectiveFreshness,
assertManifestCompatible,
encodeManifestSigningPayload,
validateSignedDirective,
validateSignedManifest,
} from '@getcortexlabs/otto-protocol';
const { directive } = validateSignedDirective(rawDirective);
assertDirectiveFreshness(directive, lastAppliedSeq);
const { manifest } = validateSignedManifest(rawManifest);
const signingPayload = encodeManifestSigningPayload(manifest);
assertManifestCompatible(manifest, {
appId: 'com.getcortexlabs.example',
platform: 'ios',
targetBuild: '42',
runtimeContract: 'ios-rc-8f4e2a1b',
});Technical eligibility is separate from App Store and Google Play review rules. Interpreted JavaScript and updatable assets stay within the capabilities already compiled into the installed binary; native changes go through normal store releases.
| Change | OTA eligible? |
|---|---|
| Bug fixes in TypeScript/JavaScript logic or state handling | Yes, if compatible with existing native metadata and bindings |
Layout, style, copy and updatable asset changes (~/...) |
Yes |
| Adding or updating a native iOS/Android SDK, Pod, Gradle dependency or permission | No — requires a new store binary |
Upgrading @nativescript/ios, @nativescript/android or native bootstrapper code |
No — requires a new store binary |
| Calling a native API or registering a native subclass missing from build-time metadata | No — requires a new store binary (checked by otto fingerprint / pack, #11) |
@getcortexlabs/otto-cli ships the otto binary for key management, per-platform runtime compatibility fingerprinting, release packaging, offline verification and local fault-injection testing:
# 1. Generate an Ed25519 signing keypair outside the app source tree
otto keygen --key-id prod-2026 --out-dir ~/.otto-keys
# 2. Record a store-binary compatibility baseline after building a release binary
otto fingerprint --platform ios --project . \
--write-baseline ./otto.baseline.ios.json --write-config
# 3. Pack and sign a prepared Webpack 5 bundle (refuses automatically if native drift is detected)
otto pack --platform ios --project . --baseline ./otto.baseline.ios.json \
--release-id ota-105 --private-key ~/.otto-keys/prod-2026.private.pem \
--key-id prod-2026 --out ./dist-otto/ota-105
# 4. Verify signature, inventory hashes and baseline compatibility offline in CI
otto verify --bundle ./dist-otto/ota-105 --config ./otto.config.json \
--baseline ./otto.baseline.ios.json
# 5. Serve locally for device/simulator testing (supports fault modes via --mode)
otto serve --bundle ./dist-otto/ota-105 \
--private-key ~/.otto-keys/prod-2026.private.pem --key-id prod-2026 --port 18787otto fingerprint hashes five separate sections per platform: NativeScript runtime + native OTA bootstrapper code, resolved native plugins, normalized App_Resources config/permissions, generated platform metadata (metadata-*.bin on iOS, assets/metadata/*.dat on Android) and normalized static bindings (sbg-bindings.txt on Android plus JS-to-native class/protocol registrations). Pure JavaScript, CSS and asset edits keep the contract unchanged; adding a native plugin, permission, runtime bump or new native subclass exits with code 2 and prints the exact section diff.
| Package | Role | Status |
|---|---|---|
@getcortexlabs/otto-protocol |
Schemas, JCS canonical serialization, path safety, validators, BootState, lifecycle events and error codes |
Delivered (M0, #3) |
@getcortexlabs/otto-nativescript |
Native iOS/Android boot selectors, CryptoKit / Tink Ed25519 + SHA-256 verification, streaming downloader with content-addressed local reuse (#17), atomic staging + GC, updates SDK API and after-prepare config hook |
Delivered (M0–M1 + #15–#17) |
@getcortexlabs/otto-cli |
keygen, per-platform fingerprint (incl. Android V8 snapshot/codeCache checks), Webpack 5 & Vite pack, offline verify and local fixture serve with 9 fault modes |
Delivered (M2 + #15–#16) |
fixtures/vue-mavis-app |
Reference Webpack 5 NativeScript-Vue 3 + Mavis + Jolt release app proving all 8 OTA scenarios | Passing 8/8 on iOS 26.2 & physical Android 16 R8 |
fixtures/vite-app |
Reference @nativescript/vite 8.0.24 production ESM app proving all 8 OTA scenarios (import(...), require(esm), ns:util, Web Worker, Android codeCache: true, >99% asset reuse) |
Passing 8/8 on iOS 26.2 & physical Android 16 R8 |
fixtures/boot-spike |
Minimal NativeScript 9.1 Webpack 5 release boot spike | Passing on iOS 26.2 & Android 16 R8 |
docs/ |
Bilingual (EN / pt-BR) VitePress + Jolt Web documentation with interactive lifecycle, security and recovery labs |
Delivered (M3, #14) |
otto-nativescript only claims support for runtime and bundler combinations verified on release builds. See SUPPORT_MATRIX.md for the exact pinned versions and verified native hook points.
- Verified release targets:
@nativescript/core9.1.4,@nativescript/ios9.1.1,@nativescript/android9.1.3 (withandroid.codeCache: trueand R8minifyEnabled true), Webpack 5 (@nativescript/webpack5.0.43) and Vite 8 (@nativescript/vite8.0.24) production.mjsoutputs. - Explicitly unsupported: Legacy Android V8 heap snapshots (
libsnapshot.so/TNSSnapshot.blob, removed in NativeScript 7 and rejected byotto packunless--allow-snapshotis passed), mid-session hot swaps without process restart, and automatic rollback of local SQLite schemas or persisted preferences.
The public repository owns the SDK, CLI, protocol and documentation source. npm run docs:build also prepares @getcortexlabs/otto-docs, which is released at the same version as the libraries. The private Otto service pins that package and serves it at https://otto.getcortexlabs.com/docs/; changes here reach the site when it updates the package and redeploys. The generated /docs/build-info.json identifies the version and source commit.
Version 0.2 adopts the Otto package names, the otto command and otto.config.json. See MIGRATING.md when moving an existing installation.
Requires Node.js >= 22.
npm install
npm run check # format:check, build, typecheck, vitest
npm test # unit tests and Ed25519 golden vectors
npm run docs:dev # local VitePress + Jolt documentation server
npm run docs:build # production static docs build
npm run format # prettier --write .To build the release boot spike locally with the NativeScript CLI installed:
npm install --prefix fixtures/boot-spike
ns build ios --release --path fixtures/boot-spike --env.productionFor Android release builds, pass a signing keystore (--key-store-path, --key-store-password, --key-store-alias, --key-store-alias-password); fixtures/boot-spike/App_Resources/Android/app.gradle enables R8 minification (minifyEnabled true) so the plugin's keep rules are exercised on every build.
MIT. Maintained by Rafael Augusto and Cortex Labs.
