Phase 2 Android: jniLibs packaging + unified rollup loader plugin#17
Merged
Conversation
Phase 2 Android, completing Phase 2 across both platforms. Mirrors the
iOS xcframework work landed earlier on this branch — same shape, same
naming convention, same rollup-plugin loader-pattern transform — only
the runtime-helper banner and the file extension differ.
scripts/build-backend.ts:
- Replaces the `assets/nodejs-native/<abi>/...` write with
`android/src/main/jniLibs/<abi>/lib<name>__<version>.so`. One
`.so` per (name, version) instance × ABI, so multi-version dep
trees (sodium-native@4.3.3 + @5.1.0, better-sqlite3@11.10.0 +
@12.9.0) get distinct slots. Reuses `NATIVE_PAIRS` already
enumerated for the iOS xcframework wrap.
- Lifts `findNodeForArch(name, version, target)` and
`androidAbiForArch(arch)` to top-level helpers so iOS and
Android share them. The iOS xcframework wrap loop is unchanged
in shape — just calls the lifted helper.
backend/rollup-plugins:
- Renames `rollup-plugin-ios-addon-loader.js` to
`rollup-plugin-addon-loader.js`. The loader-pattern transform
(rewrite `bindings`/`node-gyp-build`/`require.addon` callsites
to `__loadAddon(name, version)`) is platform-agnostic; only the
runtime helper banner differs.
- Adds `androidAddonLoaderBanner` alongside the existing
`iosAddonLoaderBanner`. Both define `__loadAddon(name, version)`
with cache key `name + '__' + version`; the only difference is
the `process.dlopen` argument: bare `lib<key>.so` on Android
(Bionic linker namespace resolves against APK mmap region), or
`<NATIVE_LIB_DIR>/<key>.framework/<key>` on iOS.
- Deletes `rollup-plugin-native-paths.js`. Its job (route
bare-resolver paths through node_modules/<pkg>/prebuilds/...)
no longer applies — `.so` files don't live under node_modules
on Android any more.
backend/rollup.config.js:
- Both outputs use the unified plugin. Per-platform banners on
`output.banner`. iOS-specific bits (maps-stub alias) stay
iOS-only.
android/build.gradle:
- `jniLibs.srcDirs` adds `'src/main/jniLibs/'` (alongside the
existing `'libnode/bin/'` for the prebuilt nodejs-mobile
libnode.so).
- `packagingOptions { jniLibs { useLegacyPackaging false } }` —
keeps `.so` files uncompressed and aligned in the APK so
Bionic can mmap them in place when the manifest disables
extraction.
android/src/main/AndroidManifest.xml:
- `<application android:extractNativeLibs="false">`. Pairs with
`useLegacyPackaging=false` above. Required by the rolled-up
backend's bare-name `process.dlopen` calls — see canonical
plan §0.1.
android/src/main/java/com/comapeo/core/NodeJSService.kt:
- Drops the `copyAssetFolder(nodejs-native/<abi>/, ...)` overlay
extraction step in `start()`. Native code now lives in the
APK's `lib/<abi>/` segment, mmap'd at load time. JS bundle
extraction (`copyAssetFolder(NODEJS_PROJECT_DIRNAME, ...)`)
stays — the rolled-up `index.mjs` still needs a filesystem
path to start nodejs-mobile from.
- Removes the now-unused `getCurrentABIName()` `external fun`
declaration. `nodeNativeAssetsDir` field, `NODEJS_NATIVE_ASSETS_DIRNAME`
const both gone.
android/src/main/cpp/jni-bridge.cpp:
- Removes the JNI-side `getCurrentABIName` function + its
`registerNatives` entry + the `CURRENT_ABI_NAME` macro. No
callers — it was only used by the removed asset-overlay step.
.gitignore:
- Adds `android/src/main/jniLibs/`. Removes the now-stale
Phase-1 / Phase-2 iOS guard-rail comments — the per-platform
generated paths are under a single comment block.
iOS sim regression check: 4/4 tests pass (smoke + lifecycle +
ComapeoCoreModule pair). Android emulator + APK-shape verification
land on next CI run.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This was referenced Apr 28, 2026
gmaclennan
added a commit
that referenced
this pull request
Apr 28, 2026
## Summary Cleanup pass after Phase 2 (PRs #15, #16, #17) landed on `main`. - **Open follow-up issues** for everything deferred from those PRs: #19–#32 (Android JNI stdio drain, iOS device smoke test, TestFlight ritual, fetch polyfill, maps plugin re-introduction, Phase 3 smoke test, Phase 4 socket-transport shim, IPC backpressure, 16KB page alignment audit, Android lifecycle parity, `abiFilters`, blobs over UDS, web platform). - **Remove implemented plan docs** — `docs/Todos.md`, `docs/phase-2-android-jnilibs-plan.md`, `docs/phase-2-xcframework-plan.md`, `docs/unified-js-bundle-ios-plan.md`. `docs/build-architecture-plan.md` stays (Phase 3-4 still open) with its inline status banners updated to point at the merged PRs. - **Trim history-oriented comments** throughout `scripts/build-backend.ts`, `backend/`, `ios/`, and `android/`: drop "Phase 1 wrote X / Phase 2 ships Y" framing, references to the external validating harness in `digidem/nodejs-mobile-bare-prebuilds`, and lingering `state.sock` naming in favour of `control.sock`. - **Refresh `agents.md`** to describe the unified rolled-up backend, jniLibs/xcframework packaging, and the current test layout. Replace the regression-test history table with a forward-looking "Open follow-ups" list pointing at the new issues. No behaviour changes. ## Test plan - [x] `tsc --noEmit -p scripts/tsconfig.json` clean (only comment edits there) - [ ] CI Android workflow green - [ ] CI iOS workflow green (simulator + device-build) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
gmaclennan
added a commit
that referenced
this pull request
Jun 22, 2026
## Optic Release Automation This **draft** PR is opened by Github action [optic-release-automation-action](https://github.com/nearform-actions/optic-release-automation-action). A new **draft** GitHub release [v1.0.0-pre.2](https://github.com/digidem/comapeo-core-react-native/releases/tag/untagged-c499977757c9745e56b2) has been created. Release author: @gmaclennan #### If you want to go ahead with the release, please merge this PR. When you merge: - The GitHub release will be published - The npm package with tag pre will be published according to the publishing rules you have configured - No major or minor tags will be updated as configured #### If you close the PR - The new draft release will be deleted and nothing will change ## What's Changed * Android Testing Infrastructure & Bug Fixes by @gmaclennan in #3 * chore: prebuild example/android; harden instrumented tests by @gmaclennan in #10 * Integrate @comapeo/core via IPC over Unix sockets by @gmaclennan in #5 * chore: adjust repo setup by @achou11 in #12 * chore: minor fixes based on expo-doctor by @achou11 in #13 * Add iOS support & test infrastructure by @gmaclennan in #6 * chore: add architecture docs & plans by @gmaclennan in #11 * update some native deps used in backend by @achou11 in #14 * iOS Phase 1: unified JS bundle + smoke test (simulator-only) by @gmaclennan in #15 * iOS Phase 2: xcframework Embed & Sign for native addons by @gmaclennan in #16 * Phase 2 Android: jniLibs packaging + unified rollup loader plugin by @gmaclennan in #17 * chore: post-Phase-2 cleanup — comments, plan docs, agents.md by @gmaclennan in #33 * android: read abiFilters from reactNativeArchitectures (#30) by @gmaclennan in #35 * refactor: simplify build-backend.ts; rollup writes directly to native asset trees by @gmaclennan in #34 * chore: fix eslint configuration by @achou11 in #41 * android: audit 16 KB page alignment on every shipped .so by @gmaclennan in #43 * Add rootkey persistence and lifecycle state management by @gmaclennan in #36 * chore: move example app into apps directory by @achou11 in #18 * refactor: per-component lifecycle state with derived ComapeoState by @gmaclennan in #47 * android: fold waitForFile into connect retry loop by @gmaclennan in #52 * chore: add e2e testing app by @achou11 in #49 * fix(android): drop setUnlockedDeviceRequired from rootkey wrapper key by @gmaclennan in #57 * fix(backend): cache stopping/error frames for late joiners by @gmaclennan in #58 * fix(ios-tests): wait for STOPPING before signalling node exit by @gmaclennan in #59 * fix(android): drain JNI stdio pumps before returning from node::Start by @gmaclennan in #60 * Sentry integration: Phase 1 + Phase 2a + Phase 2b by @gmaclennan in #54 * feat(backend): polywasm-backed undici on iOS, re-enable maps plugin by @gmaclennan in #62 * ci: drop unreliable Android emulator snapshot caching by @gmaclennan in #64 * feat(sentry): land Phase 3 — backend loader + RPC tracing by @gmaclennan in #63 * fix(ios-tests): serialise STOPPING/STOPPED observers in testFullLifecycleStateTransitions by @gmaclennan in #71 * use npm list instead of custom traversal to get native module versions by @achou11 in #70 * feat(sentry): land Phases 6 + 7a — Android exit reasons & iOS MetricKit app-exit telemetry by @gmaclennan in #72 * fix(sentry): make exit telemetry lossless and stop cross-process clobbering by @gmaclennan in #84 * chore(e2e): add e2e tests on browserstack via Maestro by @achou11 in #56 * feat(sentry): migrate to @sentry/react-native v8; exit telemetry as Application Metrics by @gmaclennan in #73 * Map server integration by @gmaclennan in #86 * chore(deps): upgrade to Expo SDK 56 (React Native 0.85) by @gmaclennan in #87 * chore(ci): add release workflow by @gmaclennan in #90 * chore: fix npm script and release build script by @gmaclennan in #91 * chore(pack): don't try to package build files by @gmaclennan in #92 * fix: start fastify listening by @gmaclennan in #93 * perf(backend): switch bundler from rollup to rolldown by @gmaclennan in #94 * fix(ci): ignore-scripts in ios npm installs by @gmaclennan in #96 * fix(ci): replace --ignore-scripts with npm strict-allow-scripts allowlist by @gmaclennan in #106 * feat(config): let the consuming app supply the default project config by @gmaclennan in #95 * chore(release): merge prerelease branch. by @gmaclennan in #110 ## New Contributors * @achou11 made their first contribution in #12 **Full Changelog**: https://github.com/digidem/comapeo-core-react-native/commits/v1.0.0-pre.2 <!-- <release-meta>{"id":342868678,"version":"v1.0.0-pre.2","npmTag":"pre","opticUrl":"https://optic-zf3votdk5a-ew.a.run.app/api/generate/"}</release-meta> -->
gmaclennan
added a commit
that referenced
this pull request
Jun 22, 2026
## Optic Release Automation This **draft** PR is opened by Github action [optic-release-automation-action](https://github.com/nearform-actions/optic-release-automation-action). A new **draft** GitHub release [v1.0.0-pre.2](https://github.com/digidem/comapeo-core-react-native/releases/tag/untagged-352a6c41c12fd02dec37) has been created. Release author: @gmaclennan #### If you want to go ahead with the release, please merge this PR. When you merge: - The GitHub release will be published - The npm package with tag pre will be published according to the publishing rules you have configured - No major or minor tags will be updated as configured #### If you close the PR - The new draft release will be deleted and nothing will change <!-- Release notes generated using configuration in .github/release.yml at 7fe80b4 --> ## What's Changed ### 🚀 Features * Integrate @comapeo/core via IPC over Unix sockets by @gmaclennan in #5 * Add iOS support & test infrastructure by @gmaclennan in #6 * iOS Phase 1: unified JS bundle + smoke test (simulator-only) by @gmaclennan in #15 * iOS Phase 2: xcframework Embed & Sign for native addons by @gmaclennan in #16 * Phase 2 Android: jniLibs packaging + unified rollup loader plugin by @gmaclennan in #17 * android: read abiFilters from reactNativeArchitectures (#30) by @gmaclennan in #35 * Add rootkey persistence and lifecycle state management by @gmaclennan in #36 * Sentry integration: Phase 1 + Phase 2a + Phase 2b by @gmaclennan in #54 * feat(backend): polywasm-backed undici on iOS, re-enable maps plugin by @gmaclennan in #62 * feat(sentry): land Phase 3 — backend loader + RPC tracing by @gmaclennan in #63 * feat(sentry): land Phases 6 + 7a — Android exit reasons & iOS MetricKit app-exit telemetry by @gmaclennan in #72 * feat(sentry): migrate to @sentry/react-native v8; exit telemetry as Application Metrics by @gmaclennan in #73 * Map server integration by @gmaclennan in #86 * feat(config): let the consuming app supply the default project config by @gmaclennan in #95 ### 🐛 Bug Fixes * fix(android): drop setUnlockedDeviceRequired from rootkey wrapper key by @gmaclennan in #57 * fix(backend): cache stopping/error frames for late joiners by @gmaclennan in #58 * fix(ios-tests): wait for STOPPING before signalling node exit by @gmaclennan in #59 * fix(android): drain JNI stdio pumps before returning from node::Start by @gmaclennan in #60 * fix(ios-tests): serialise STOPPING/STOPPED observers in testFullLifecycleStateTransitions by @gmaclennan in #71 * fix(sentry): make exit telemetry lossless and stop cross-process clobbering by @gmaclennan in #84 * fix: start fastify listening by @gmaclennan in #93 * fix(ci): ignore-scripts in ios npm installs by @gmaclennan in #96 * fix(ci): replace --ignore-scripts with npm strict-allow-scripts allowlist by @gmaclennan in #106 * fix(release): stop `npm pack --dry-run` leaking dry-run into backend install by @gmaclennan in #129 ### ⚡ Performance * perf(backend): switch bundler from rollup to rolldown by @gmaclennan in #94 ### ⬆️ Dependencies * update some native deps used in backend by @achou11 in #14 * chore(deps): upgrade to Expo SDK 56 (React Native 0.85) by @gmaclennan in #87 ### 🏗️ Maintenance * Android Testing Infrastructure & Bug Fixes by @gmaclennan in #3 * chore: prebuild example/android; harden instrumented tests by @gmaclennan in #10 * chore: adjust repo setup by @achou11 in #12 * chore: minor fixes based on expo-doctor by @achou11 in #13 * chore: add architecture docs & plans by @gmaclennan in #11 * chore: post-Phase-2 cleanup — comments, plan docs, agents.md by @gmaclennan in #33 * refactor: simplify build-backend.ts; rollup writes directly to native asset trees by @gmaclennan in #34 * chore: fix eslint configuration by @achou11 in #41 * android: audit 16 KB page alignment on every shipped .so by @gmaclennan in #43 * chore: move example app into apps directory by @achou11 in #18 * refactor: per-component lifecycle state with derived ComapeoState by @gmaclennan in #47 * android: fold waitForFile into connect retry loop by @gmaclennan in #52 * chore: add e2e testing app by @achou11 in #49 * ci: drop unreliable Android emulator snapshot caching by @gmaclennan in #64 * use npm list instead of custom traversal to get native module versions by @achou11 in #70 * chore(e2e): add e2e tests on browserstack via Maestro by @achou11 in #56 * chore(ci): add release workflow by @gmaclennan in #90 * chore: fix npm script and release build script by @gmaclennan in #91 * chore(pack): don't try to package build files by @gmaclennan in #92 * chore(release): merge prerelease branch. by @gmaclennan in #110 * ci(e2e): retry BrowserStack builds on infra-class flakes by @gmaclennan in #113 ### Other Changes * ci: derive changelog labels from PR titles + add Dependabot by @gmaclennan in #114 ## New Contributors * @achou11 made their first contribution in #12 * @optic-release-automation[bot] made their first contribution in #112 **Full Changelog**: https://github.com/digidem/comapeo-core-react-native/commits/v1.0.0-pre.2 <!-- <release-meta>{"id":342970724,"version":"v1.0.0-pre.2","npmTag":"pre","opticUrl":"https://optic-zf3votdk5a-ew.a.run.app/api/generate/"}</release-meta> -->
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Completes Phase 2 of
docs/build-architecture-plan.md— the symmetric Android counterpart to PR #16 (iOS xcframework Embed & Sign). Native.nodefiles now ship aslib<name>__<version>.sounderandroid/src/main/jniLibs/<abi>/, mmap'd from the APK by Bionic's per-app linker namespace at load time. The runtime asset extraction step (copyAssetFolder("nodejs-native/<abi>", ...)) and the legacyrollup-plugin-native-paths.jsare gone. The iOS-only addon-loader rollup plugin from #16 is generalised to a single platform-agnostic plugin with per-platform banners.Detailed plan:
docs/phase-2-android-jnilibs-plan.md. One deviation from the original plan: versioned filenames (lib<name>__<version>.so) are adopted from the start instead of deferred — the dep tree already carries multi-versionsodium-native(4.3.3 + 5.1.0) andbetter-sqlite3(11.10.0 + 12.9.0), surfaced by the iOS Phase 2 work, so the multi-version path is the reference path.Changes
scripts/build-backend.tsassets/nodejs-native/<abi>/...write; emitslib<name>__<version>.soper (name, version) instance × ABI intojniLibs/<abi>/. LiftsfindNodeForArch+androidAbiForArchto top-level helpers shared with the iOS xcframework wrap.backend/rollup-plugins/rollup-plugin-addon-loader.js(renamed fromrollup-plugin-ios-addon-loader.js)iosAddonLoaderBanner,androidAddonLoaderBannerdiffer only in theprocess.dlopenargument.backend/rollup-plugins/rollup-plugin-native-paths.jsbackend/rollup.config.jsoutput.banner.android/build.gradlejniLibs.srcDirs += 'src/main/jniLibs/',packagingOptions.jniLibs.useLegacyPackaging = false.android/src/main/AndroidManifest.xml<application android:extractNativeLibs="false">.android/src/main/java/com/comapeo/core/NodeJSService.ktnodejs-nativeoverlay extraction instart(); removes unusedgetCurrentABINameexternal fun,nodeNativeAssetsDirfield,NODEJS_NATIVE_ASSETS_DIRNAMEconst.android/src/main/cpp/jni-bridge.cppgetCurrentABINameJNI export +CURRENT_ABI_NAMEmacro (no callers)..gitignoreandroid/src/main/jniLibs/.Test plan
Local validation against the running iOS simulator + Android emulator on this commit:
CoreManagerSmokeTest,ServiceLifecycleTest, bothComapeoCoreModuleTests. Confirms the rollup plugin rename didn't regress iOS.BUILD SUCCESSFUL.process.dlopen('lib<key>.so')works end-to-end against the APK mmap region withextractNativeLibs="false".Out of scope (deferred follow-ups)
NodeJSService.ktJNI stdio pump drain fix (canonicalbuild-architecture-plan.md§0.4 / §8). Important for diagnostics — uncaught backend exceptions are routinely lost to the pthread_detach race today — but separable from packaging. Recommend its own PR right after this one.globalThis.fetchpolyfill; maps-stubconsole.warn.readelf -l | grep LOADon each shipping.so).🤖 Generated with Claude Code