Engineering BlueprintExpoReact NativeTypeScriptSQLiteAndroidiOSSpeakOnMobile

SpeakOn Phase 4: Pure CNG Expo 57 Client, Offline expo-sqlite Cache, and LAN/USB Pairing

Building SpeakOn Mobile with Expo SDK 57 Continuous Native Generation (com.aldeon.speakon), CommonJS withLocalNetwork plugins, Bun Skia postinstall wiring…

Célio Vieira644 words4 min read

Key Takeaways (TL;DR)

Summary
  • Pure Continuous Native Generation Without Checked-In Native Trees — Keeping an Expo mobile repository clean and reproducible means keeping android/ and ios/ out of source…
  • Local Network Plugin & Native Build Gotchas — Three concrete tooling constraints shaped how the native build works cleanly under Bun and @expo/config:
  • Offline-First expo-sqlite Architecture & Testability — Importing expo-sqlite directly in shared TypeScript files pulls in react-native/index.js, whose Flow import typeof *…
  • Verification, Native APK Compilation, and CI — Next up in Phase 5: building the Mandarin Studio backend inside speakon/services/app/mandarin/ with checksummed datasets…

Pure Continuous Native Generation Without Checked-In Native Trees#

Keeping an Expo mobile repository clean and reproducible means keeping android/ and ios/ out of source control while still verifying full native builds on every change. In Phase 4 of SpeakOn, we built the standalone open-source mobile client (Celio1878/speakon-mobile, com.aldeon.speakon) on Expo SDK 57, Expo Router, and strict TypeScript.

Every commit stays pure Continuous Native Generation (CNG), while CI validates npx expo prebuild --clean for both Android and iOS and local Linux verification compiles the full native Android debug APK before discarding generated folders.

Local Network Plugin & Native Build Gotchas#

Three concrete tooling constraints shaped how the native build works cleanly under Bun and @expo/config:

  1. CommonJS Local Config Plugin (plugins/withLocalNetwork.js + .d.ts): @expo/config transpiles app.config.ts directly, but delegates nested require("./plugins/...") calls to Node without a TypeScript loader. Exporting withLocalNetwork from CommonJS plugins/withLocalNetwork.js alongside a companion .d.ts declaration satisfies strict tsc --noEmit, bun test, and Expo Prebuild simultaneously—injecting android:usesCleartextTraffic="true" on Android and NSAllowsLocalNetworking, _http._tcp Bonjour discovery, plus camera/microphone privacy prompts on iOS.
  2. Skia Prebuilt Binaries Under Bun (trustedDependencies): Bun blocks dependency postinstall lifecycle scripts by default, which skipped @shopify/react-native-skia's scripts/install-libs.js and caused Android CMake to fail looking for libskia.a. Adding "@shopify/react-native-skia" to trustedDependencies in package.json restored the 24 MB arm64-v8a/libskia.a binary cleanly and kept bun install --frozen-lockfile passing with zero untrusted packages.
  3. Architecture & Gradle Tuning: expo-build-properties pins Android ABIs to ["arm64-v8a", "x86_64"] and sets org.gradle.workers.max=4 so Linux local builds finish cleanly without memory thrashing.

Offline-First expo-sqlite Architecture & Testability#

Importing expo-sqlite directly in shared TypeScript files pulls in react-native/index.js, whose Flow import typeof * syntax cannot be parsed directly by bun test. Instead of heavy bundler mocks, we split persistence cleanly:

  • src/storage/offlineCache.ts: Contains pure SQLite WAL schema initialization and CRUD queries (cached_profile, cached_sessions, cached_turns, cached_analytics, sync_meta) parameterized over a minimal SqliteDriver interface.
  • src/storage/sqliteCache.ts & src/__tests__/sqliteCache.test.ts: Production screens bind expo-sqlite, while unit tests bind bun:sqlite directly against real SQLite WAL tables and ON DELETE CASCADE constraints.
  • src/storage/secureStore.ts: Keeps desktop URLs, access_token / refresh_token, and single-use pairing credentials (X-SpeakOn-Device) strictly inside encrypted expo-secure-store.

LAN QR / USB Pairing, Passwordless Auth & Voice Transport#

  • Flexible Desktop Pairing (app/pair.tsx & src/lib/serverUrl.ts): Supports camera QR scanning (speakon://pair?u=http://<lan-ip>:8000&c=<code>), manual RFC1918 LAN URLs, and USB adb reverse tcp:8000 tcp:8000 loopback (http://127.0.0.1:8000), while rejecting cleartext public hosts. /health probes report round-trip latency and discover active providers cleanly.
  • Passwordless Authentication (app/login.tsx): Supports 6-digit Email OTP always and reveals Sign in with Apple / Sign in with Google only when enabled by both build capabilities and desktop /api/auth/providers, with zero password inputs anywhere in source.
  • Dual Voice Pipeline (src/audio/voiceTransport.ts): Combines expo-audio .m4a Push-to-Talk uploads (POST /api/sessions/{id}/turn), @siteed/audio-studio 16 kHz mono PCM16 WebSocket streaming with { type: "cancel" } barge-in, speaker/earpiece routing (shouldRouteThroughEarpiece), tone-colored Pinyin toggles, and bottom sheets for grammar corrections and pronunciation breakdown.

Verification, Native APK Compilation, and CI#

  • Strict Types & Unit Tests: tsc --noEmit reported 0 errors, bun test passed 11 / 11 tests (77 assertions) across URL normalization, i18n EN/PT key parity, Pinyin tone parsing, source security checks, Expo plugin transforms, and real SQLite WAL persistence.
  • Expo Prebuild & Android APK Build: Both npx expo prebuild --platform ios --no-install --clean and npx expo prebuild --platform android --no-install --clean succeeded cleanly; ./android/gradlew -p android assembleDebug executed 754 tasks cleanly in 8 minutes, producing a 189 MB native app-debug.apk before cleaning generated directories.
  • Live Pairing E2E & Public CI: Verified live Mailpit OTP login, parsePairingUri() QR parsing, /api/pairing/claim, X-SpeakOn-Device authenticated calls to /api/sessions and /api/analytics/streak, and refresh token rotation against speakon-services. On GitHub (Celio1878/speakon-mobile develop), Gitleaks Secret Scan (47442115455) and CI (47442115428) both passed with zero secrets leaked.

Next up in Phase 5: building the Mandarin Studio backend inside speakon/services/app/mandarin/ with checksummed datasets, bilingual Foundations curriculum, jieba/pypinyin/OpenCC, AI dissectors/coaches, FSRS scheduling, and signed offline SQLite packs.

Célio Vieira

Célio Vieira

Founder & Architect

Engineering applied AI systems, distributed cloud platforms, and the Aldeon umbrella venture ecosystem.

Related Technical Dispatches

View all 90