Skip to content

Make the preview APK reproducible from its tag #26

Backlog

Description

@juancguerrerodev

Why

Anyone can build Hermit from the tag a preview APK came from, but the result doesn't match the published APK byte for byte, and nothing checks it. The PRD lists the reproducible APK as open (SL-45 and NFR-15 in docs/prd/hermit-prd.md). A rebuild that matches, apart from the signature, is how people can trust that the APK is the code they read.

What to do

  1. Make the recipe complete. Before it builds, .github/workflows/release-apk.yml writes the version from the tag, and a versionCode equal to the workflow's run number, into apps/mobile/app.json. Put the same step in the recipe in docs/devices.md ("Or build it yourself"), and print the versionCode in the release notes so a rebuild can use it.
  2. Build twice from the same tag, on two machines or two clean clones, following docs/devices.md. Compare the APKs with the signature left out: unzip both and compare every file except META-INF/, or use diffoscope.
  3. Find and remove each source of difference, such as timestamps, file order, absolute paths, the JavaScript bundle or the native builds. List what you find in the pull request, even the parts you couldn't fix.
  4. When two builds match, add a script or a CI job that checks it, and put the recipe in the release notes.

Done when

  • Two builds from the same tag give APKs that match apart from the signature, and a script or a CI job shows it.
  • docs/devices.md and the site's download page say so, and the release notes carry the recipe.

How to check

Build twice as docs/devices.md says, then compare the unzipped APKs without META-INF/.

Keep in mind

  • Compare unsigned contents. Never ask for the preview key, and never commit a keystore or a password.
  • The app gains no network call. Build-time downloads are fine when their versions are pinned.

Activity

  1. added
    help wanted
    accepted
    on Nov 26, 2026
  2. saurabhbhoir456 commented on Dec 6, 2026

    @saurabhbhoir456
    Contributor

    I'll take this one, step by step. Step 1 first: the same version/versionCode step .github/workflows/release-apk.yml runs, written into the "Or build it yourself" recipe in docs/devices.md, and the versionCode printed in the release notes so a rebuild can use it. Steps 2-4 (build twice, compare apart from the signature, remove each source of difference, then a check) need a JDK 17 + Android SDK/NDK toolchain installed here first; I'll report what the comparison finds, including anything that stays unfixed.

  3. saurabhbhoir456 commented on Dec 6, 2026

    @saurabhbhoir456
    Contributor

    Steps 2-3 findings: two builds compared, and a same-path rebuild

    Built the tag v0.1.0-preview.1 (5cc0e9f) twice from clean copies on this machine (WSL2 Linux, matching the release workflow's OS), at two different absolute paths (~/ba and ~/hermit-build-b), with the version/versionCode step from #289 applied identically (0.1.0-preview.1 / 412), then a third time back at the first path. Toolchain: Node 24.11.0, Temurin 17.0.21.1, pnpm 10.15.1 (lockfile), Android SDK platform 37, build-tools 37.0.0, NDK 29.0.14206865, CMake 3.22.1, Gradle 9.4.1 (the wrapper's version; fetched from a mirror with a verified SHA-256 because release-assets.githubusercontent.com is unreachable from this machine). Signing was the local debug key (no preview key involved); comparison excludes META-INF/ throughout.

    Different paths (A vs B): 971 of 984 entries identical

    Same entry names, same order, and zero timestamp differences across all 984 non-META-INF entries. 13 entries differ:

    • assets/index.android.bundle (+192 bytes in the longer path): the QVAC worker bundle embeds absolute file:// imports for @qvac/sdk subpaths. That is @qvac/sdk's createSdkImportResolver (dist/src/commands/bundle/resolve-sdk-import.js:54), which rewrites @qvac/sdk/... specifiers to pathToFileURL(realpath) on purpose (so bare-* resolution anchors next to the SDK's deps under pnpm). Bare-pack embeds those URLs verbatim (8 occurrences; +12 chars x 8 x 2 bytes UTF-16 = the exact +192). The bundle manifest's content id differs as a consequence.
    • 12 native libraries: 11 differ only in the 20-byte GNU build-id (one range each, at the build-id note). The build-id is hashed before stripping, over output that includes DWARF compilation-directory paths, so it changes with the clone path even though the stripped bytes are otherwise identical. The twelfth (libreact_codegen_rnscreens.so) also retains clone paths in its debug strings in the shipped library.

    Same path (A vs C): 984 of 984 identical

    A third build, from a fresh copy placed back at A's exact path, matches A apart from META-INF/: same names, order, timestamps, sizes, CRCs and compression on every entry. So the build is otherwise deterministic, and the absolute clone path is the only source of difference found. (The wallet worklet bundle is also byte-size identical across both Linux paths; a Windows build differed — different OS/toolchain, out of scope here.)

    Windows-only findings (not needed for the Linux comparison)

    Building on Windows needed clone-local adaptations, worth knowing before anyone follows docs/devices.md there: Node 26 refuses .cmd spawns without a shell (worklets/wallet/build.mjs spawns npm), the Bare binary is bare.exe, link.mjs derives its folder from URL(import.meta.url).pathname and doubles the drive prefix (\\?\C:\C:\...), scripts/qvac-bundle.mjs passes Windows paths to dynamic import() (needs pathToFileURL), the Windows NDK clang ships no default-target config so CMake's link line (no --target=) falls back to the host target and its lld rejects the ELF flags in flags.cmake (a clang++.cfg with --target=aarch64-linux-android24 next to the binary fixes it), and deep Temp\opencode\... clone paths exceed CMake's 250-char object limit (short root paths work). The Gradle wrapper download also cannot reach release-assets.githubusercontent.com from this machine.

    Proposed step 4

    Build in a container at one fixed absolute path (for example /build/hermit) with the workflow's pinned toolchain, in both the recipe and eventually the release workflow itself, so the published APK and a rebuild share the same embedded paths. The check script builds twice at that path from clean copies and compares the APKs apart from META-INF/ (entry list, order, timestamps, sizes, CRCs), failing on any difference. That is the remaining work; the comparison above is the evidence it needs to pass.

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

    acceptedhelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions