Over-the-air updates
The creator sets up signed over-the-air updates for the NativeScript app of a Mavis project. An update carries the app's JavaScript, CSS and assets. Plugins, App_Resources and the NativeScript runtime still ship through the stores: publishing refuses a release when the native side changed since the store binary.
The commands drive the @getcortexlabs/ota-nativescript SDK in the app and its ota-ns CLI, and upload to Mobile updates in Orbit. Run them from the app directory, or from the root of a project with apps/mobile.
Set up
export ORBIT_TOKEN=<admin API token scoped to the workspace>
npx @getcortexlabs/create-mavis --ota init --orbit https://orbit.example.com --workspace <workspace ID>init:
- adds
@getcortexlabs/ota-nativescriptand@getcortexlabs/ota-cliat pinned versions and installs them, unless you pass--no-install; - writes
hooks/after-prepare/ota-nativescript-config.mjs, which embedsota.config.jsonin every build, and apostinstallscript that writes it again after a fresh clone. npm 11 and pnpm skip the install scripts of dependencies, and generated projects keephooks/out of Git; - creates the key that signs release manifests in
~/.ota-keys/<app ID>.--keyschooses another folder; a folder inside the project is refused; - registers that key's public half in Orbit, and finds or creates the key Orbit signs delivery directives with;
- writes
ota.config.jsonwith the Orbit endpoints and both public keys. It holds no private key; commit it; - adds
src/ota.tsand imports it from the app entry.
src/ota.ts creates the update client at startup with a stable installation ID, so each device stays in its rollout group. When the first screen is on display it calls markReady(), then checkAndStage() in the background. Neither waits for the network, so a launch without a connection is still confirmed. A staged update runs from the next launch.
ORBIT_TOKEN is read from the environment and is not written to the project. Running init again keeps the key, the registrations and the recorded contracts. --app-id and --key-id override the app ID from nativescript.config and the key name manifest.
Record the store binary
Each platform needs a baseline of the native side in the binary you submit:
ns build ios --release
npx @getcortexlabs/create-mavis --ota baseline --platform ios
ns build ios --releasebaseline writes ota.baseline.ios.json and sets the platform's runtime contract in ota.config.json. Build again so the submitted binary embeds that contract, and commit both files. Do the same for Android with your signing options. Record a new baseline whenever you ship a new store binary.
Publish
npx @getcortexlabs/create-mavis --ota publish --platform ios --channel stagingpublish runs ns prepare ios --release --env.production and compares the native side with the baseline. If it differs, it stops and prints the section that changed: that change needs a store build. Otherwise it packs and signs dist-ota/<release ID> with the manifest key, checks it offline with ota-ns verify, uploads the ZIP to Orbit and assigns it to the channel.
| Option | Use |
|---|---|
--channel | Deliver the release on this channel. Without it, the release is uploaded but not offered |
--rollout | Percentage of installations, 0 to 100; default 100 |
--release-id | Release name; default <platform>-<timestamp> |
--dry-run | Prepare, check, pack and verify, but do not upload |
Start on a test channel, then promote or widen the rollout from Mobile updates in Orbit, where you also pause and roll back. If someone changed the channel since it was read, Orbit answers 409 and nothing changes.
In CI, keep the manifest private key in a secret, restore it into the --keys folder before publish, and set ORBIT_TOKEN. dist-ota/ is added to .gitignore.
Test on your machine
--local points a build at ota-ns serve instead of Orbit:
npx @getcortexlabs/create-mavis --ota init --localThe endpoint becomes http://127.0.0.1:18787/check. The build may reach this machine over plain HTTP: the iOS Info.plist allows the local network, and on Android a network security config allows cleartext only to 127.0.0.1 and localhost. Build the release, record the baseline and build again as above, install it, then change something visible:
npx @getcortexlabs/create-mavis --ota publish --platform android
adb reverse tcp:18787 tcp:18787
npx @getcortexlabs/create-mavis --ota serve --platform androidpublish packs and verifies without uploading, and serve offers the newest packed release. Open the app to download and stage it, then open it again, without the server, to run it. --mode passes a fault mode to ota-ns serve, such as tampered-file. Run init with --orbit before building for the stores.