Skip to content

Build log + architecture: Solid Pod on Android (RN + nodejs-mobile) #1

Open

Description

@melvincarvalho

Living record of how this app came together, the architecture, and what's next. Companion to the JSS-side tracking issue JavaScriptSolidServer/JavaScriptSolidServer#522. The commit history has the blow-by-blow; this is the curated why.

What it is

An installable Android app that runs a real Solid Pod natively. A React Native shell embeds a full Node.js runtime (nodejs-mobile) and boots JSS in-process via createServer(). On launch: the pod serves at http://localhost:<port>/, the IdP generates signing keys, a single-user pod is created, a starter app bundle is installed on first run, and OIDC sign-in works end-to-end from a Solid app (pilot).

Architecture

  • RN shell (App.tsx) — single screen: boot status, "Pod running at ", Open-in-browser. Talks to Node over rn-bridge (status / ready / error messages).
  • Embedded Node (nodejs-assets/nodejs-project/main.js) — imports JSS createServer directly (no subprocess), applies the nodejs-mobile compat layer, finds a free port, listens, then best-effort seeds apps.
  • scripts/patch-android-assets.js — post-npm install source surgery for things that can't be fixed at runtime (see "AAPT" and "regex/crypto.hash" below).
  • specialUse foreground service (PodForegroundService.kt) — keeps the Node event loop alive when the user switches to a browser.
  • CI (.github/workflows/build.yml) — manual workflow_dispatch, builds a release APK (signed with the debug keystore for sideloading), 3-day artifact retention.

Why in-process JSS (not jspod)

jspod's start() launches JSS with spawn('jss', …). Android can't fork a CLI binary out of the asset bundle, so we bypass jspod and call javascript-solid-server's createServer() in the same process. (Tracked for jspod in #522.)

The fix phases

1. Native / React Native (get the APK to launch)

  • Enable the new architecture + SoLoader.init(this, OpenSourceMergedSoMapping) — RN 0.76 merged the libhermes_executor/react_* JNIs into libreactnative.so; the legacy bridge path crashes without this.
  • assembleRelease (not debug) so the JS bundle ships in the APK — a sideloaded debug build expects Metro and red-screens.

2. Assets (AAPT eats files)

  • AAPT silently drops directories named _ from packaged assets (oidc-provider's lib/helpers/_/). Overriding ignoreAssetsPattern didn't stick, so the patch script renames _ dirs and rewrites references before packaging.

3. nodejs-mobile runtime compat (Node 18, no ICU)

nodejs-mobile bundles an older Node without full ICU. The pod's dep graph (JSS + oidc-provider + jose + @koa/router) assumes Node 20/22. We bridge the gap in main.js (runtime polyfills) and the patch script (source rewrites where a runtime polyfill can't reach):

  • globalThis.crypto ← node:crypto.webcrypto (jose key-gen)
  • URL.parse() (Node 22.1+) polyfill
  • Intl.ListFormat minimal polyfill (no ICU)
  • Array#toReversed/toSorted/with (ES2023) polyfill
  • \p{…} / \P{…} Unicode property-escape regexes → ASCII classes (V8 rejects them) — source rewrite
  • crypto.hash() (Node 21.7+) → createHash().digest() — source rewrite (oidc-provider imports crypto as an immutable namespace, so a runtime shim can't add it)
  • chdir into the writable extracted project dir so JSS can mkdir ./pod-data

4. Runtime / lifecycle

  • Port-shopping from 5444 (Termux pm2 jspod often already holds 5444 on the same device).
  • specialUse foreground service (NOT dataSync, which Android 15 force-kills within seconds) so the pod survives backgrounding.
  • Browser <queries> for Android 11+ package visibility, or Open-in-browser silently no-ops.

5. Auth (OIDC sign-in)

Upstream issues filed

Known gaps

  • Pod data lives under the app's extracted project dir; needs a deliberate persistent path that survives app updates.
  • Sign-in only from same-origin apps on the pod (no HTTPS/cert story yet).
  • localhost-only; no LAN/remote reachability.
  • The nodejs-mobile compat layer is a growing per-API shim list — driven by oidc-provider targeting current Node LTS.

Future work

  • Native Kotlin + nodejs-mobile-android (drop React Native): leaner APK, none of the Hermes/new-arch/bundle complexity; reuses the same Node-side compat layer.
  • iOS via nodejs-mobile (RN iOS target or native Swift).
  • Persistent, user-visible pod storage + backup.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions