Files
kuentagym/docs/MOBILE.md
T
Duarte Santos b4f8bdf2fc CI: build the signed APK on every main push, and a build:ios job that waits for a Mac runner
build:apk was a manual job on main since it cost ~8 shared-runner minutes; the project runner
on the VM pays for it now, so every main push produces the APK (same key as the release,
artifact at /-/jobs/artifacts/main/browse?job=build:apk) and a broken Android build is caught
before the tag. Merge requests keep the manual button.

build:ios: mobile bundle + xcodebuild archive without a signing identity → unsigned .ipa
(AltStore/Sideloadly), tag builds also into the generic package registry opengym-ios/<ver>/.
Only exists once IOS_RUNNER_TAG names a registered Mac runner; untested until then.
2026-09-10 14:48:57 +02:00

9.1 KiB
Raw Blame History

Building the mobile app (iOS / Android)

openGym ships in two flavors from the same codebase:

Self-hosted (this repo's default) Mobile app (VITE_MOBILE=1)
Runs in any browser, against your own server natively on iPhone / Android (Capacitor shell)
Accounts passkey sign-in, one profile per person none — the phone is the account
Data synced to your server, readable on desktop stays on the device (file in the app's private storage)
Reminders Web Push from your server native local notifications, no server involved
Exercise media served by your server (img/, gif/) loaded from the jsDelivr CDN

The mobile flavor never talks to a backend by default: no sign-in screen, no sync, no telemetry. State is mirrored from localStorage into opengym-state.json in the app's private data directory on every change (iOS is allowed to evict WebView storage under pressure — the file mirror is the durable copy and is restored on launch). Backups go out through the OS share sheet instead of a browser download.

Connecting the app to your own server

On first launch the app asks how you want to use it. Alongside the fully local mode above, you can instead connect it to a self-hosted openGym server — your data then lives there, synced the same way the browser PWA does, instead of only on the phone. This is a mode of the same app, not a different build or download.

Passkeys can't be used for this: the app's WebView runs at its own origin, which never matches the real hostname WebAuthn needs. Instead you pair the device from a browser that's already signed in: Settings → "Pair the mobile app" shows a one-time code (valid 5 minutes); enter your server's address and that code in the app (same first-launch screen, or Settings → "Connect to my server" later) to finish. Notes:

  • Requires network access every time the app is used — there's no offline file mirror once connected, same as the browser PWA.
  • Use an HTTPS address if at all possible: the connection carries a bearer token instead of a cookie, and that token would otherwise cross the network in plain text.
  • "Sign out everywhere" (Settings → Account, in the browser) revokes a paired app's access too — it's the same signed session token either way, just delivered over a header instead of a cookie. See /api/pair/create and /api/pair/redeem in api/server.js for the exchange itself.
  • Settings → "Disconnect" syncs one last time, then drops the device cleanly back to local mode.

Prerequisites

  • Node 20+
  • Android: Android Studio (bundles the SDK). Java 21 for Gradle.
  • iOS: a Mac with Xcode 15+ and CocoaPods (brew install cocoapods). A free Apple ID is enough to run the app on your own iPhone (see below); paid membership is only needed for App Store distribution, which openGym doesn't do.

Build & run

cd frontend
npm install
npm run build:mobile        # VITE_MOBILE build + `cap sync` into android/ and ios/

npx cap open android        # opens Android Studio → run on emulator or device
npx cap open ios            # opens Xcode (Mac only) → set your signing team, then run

npm run build:mobile bakes the CDN media base into the bundle and copies the web build into both native projects — re-run it after every web-code change before building natively.

Heads-up: after build:mobile, frontend/dist contains the mobile bundle. Run a plain npm run build again before deploying dist to a server.

App icons & splash screens

frontend/resources/icon.svg is the 1024×1024 source (the app's dumbbell glyph on the app background). Generate all platform assets from it on a machine with the tooling:

cd frontend
npx @capacitor/assets generate --iconBackgroundColor '#0c0e12' --splashBackgroundColor '#0c0e12'

(If the generator won't take the SVG directly, export it to resources/icon.png at 1024×1024 first — any image tool can do it.)

Distribution — deliberately no app stores

openGym's mobile app is not on the Play Store or App Store, and that's a choice: no store accounts, no store rules, no yearly fees between you and an open-source app.

Android — sideload the APK

The official signed APK is in three places, all the same file:

  • opengym.duarte-santos.ch — the download page.
  • GitLab's package registry — every build under opengym-android/<version>/, with a .sha256 beside it. Direct link, no login: https://gitlab.com/api/v4/projects/85678327/packages/generic/opengym-android/<version>/openGym-<version>.apk
  • The GitLab release for that version, which links to the two above.

Android asks you to allow installs from the browser the first time — that's standard for any app outside the Play Store. Check the .sha256 if you got the file from anywhere else.

Both come out of CI: the build:apk job in .gitlab-ci.yml runs npm run build:mobile and ./gradlew assembleRelease, then zipaligns and signs the result with the release key. The job runs on every push to main too, so the newest unreleased build is always one click away (signed with the same key, installs over a release): https://gitlab.com/DuarteSantos8/opengym/-/jobs/artifacts/main/browse?job=build:apk — a 30-day job artifact, not a package, and not what the in-app updater offers. The key lives in protected CI variables (ANDROID_KEYSTORE_B64, ANDROID_KEYSTORE_PASSWORD, ANDROID_KEY_ALIAS), so it only exists on main and on v* tags — a merge request from a fork can build an APK, but gets an unsigned one and never sees the key. On a v* tag the signed APK is also pushed to the generic package registry, which is what the release links to.

To build and sign your own:

cd frontend && npm run build:mobile
cd android && ./gradlew assembleRelease            # → app/build/outputs/apk/release/app-release-unsigned.apk

# one-time: create a keystore. KEEP IT — updates must be signed with the same key,
# or Android refuses to install the new version over the old one.
keytool -genkeypair -keystore my.keystore -alias opengym -keyalg RSA -validity 10950

# align + sign (zipalign/apksigner ship with the Android SDK build-tools)
zipalign -f -p 4 app-release-unsigned.apk aligned.apk
apksigner sign --ks my.keystore --ks-key-alias opengym --out openGym.apk aligned.apk

iPhone — what's actually possible

Apple does not allow installing apps outside the App Store, so there is no .ipa download that would simply install. Your free options:

  • Self-host + PWA (recommended): open your instance in Safari → Share → Add to Home Screen. Full-screen app, no expiry, plus sync and passkeys.
  • Xcode free signing: open ios/ in Xcode with a free Apple ID as the team and run it onto your own iPhone. Apple expires the signature after 7 days; re-run from Xcode to renew.
  • AltStore: automates that 7-day re-signing over Wi-Fi via a Mac companion app.

There is a build:ios job in .gitlab-ci.yml for exactly that path: the same mobile bundle, xcodebuild archive without a signing identity, and an unsigned .ipa (plus .sha256) as job artifact — on a tag also under opengym-ios/<version>/ in the package registry — for AltStore/Sideloadly users to sign with their own Apple ID. It needs a Mac: Xcode does not run on the Linux project runner, and gitlab.com's hosted macOS runners are not on the free tier. To switch it on, register a Mac as a project runner (shell executor; Xcode, CocoaPods and Node installed; give it a tag such as macos) and set the CI/CD variable IOS_RUNNER_TAG to that tag — the job then appears in every main and tag pipeline. Until that variable exists the job is not part of any pipeline, and it has not run yet, so expect a first round of fixes. A signed build (TestFlight, App Store) would additionally need an Apple Developer Program membership, the distribution certificate and profile as protected file variables, and an -exportArchive step — none of that is set up.

Release notes for maintainers

  • Bump versionName/versionCode in android/app/build.gradle per release; keep them in step with frontend/package.json. versionCode must strictly increase or updates won't install over an existing APK. The APK is named from frontend/package.json (the CI job reads version out of it), so the two drifting apart shows up as a misnamed file.
  • Tagging vX.Y.Z is what ships everything: images, APK, release notes. Don't push a version tag you don't mean to release — v* tags are protected for that reason.
  • License: openGym is AGPL-3.0, which by itself sits badly with app-store terms of service. NOTICE.md carries an app-store exception (an additional permission under AGPL §7) granted by the copyright holder — relevant only if store distribution ever happens.
  • The app requests notification permission only when the workout-day reminder is switched on, and (on Android) declares SCHEDULE_EXACT_ALARM so the reminder fires to the minute where the user allows it.