flutter_patcher Self-Hosted Android Hot Update (frontend libapp.so)
This doc describes songloft-player's frontend self-hosted Android hot update built on flutter_patcher: it replaces the whole libapp.so on cold start, patches are auto-published as assets on every GitHub Release, and the client checks on startup, downloads on manual confirm, and takes effect on cold restart; versions that can't be hot-patched send the user to Settings to download the APK.
Bilingual: any change here must be mirrored in
docs/cn/flutter_patcher_hotupdate.md. The Bundle build merges this frontend patch and the backendlibgojni.sopatch into one update experience (one dialog, one cold restart) — see backend_hotupdate.md; this doc focuses on the frontend mechanism and the standard-build release.
Scope & boundaries
| Dimension | Conclusion |
|---|---|
| Platform | Android only. On iOS/desktop/web the plugin and our wrapper are safe no-ops |
| Hot-patchable | Any Dart under lib/, pure-Dart deps, bundled-registered Flutter assets |
| Not hot-patchable | Native Kotlin/Java/C++, AndroidManifest, res/, native plugin add/change, Flutter Engine upgrades — must ship a new APK |
| When it applies | On the next cold start after download, never in-process; the plugin has crash rollback + bad-patch blacklist |
| Channel | dev updates dev, stable updates stable, no crossing (decided by compile-time AppConfig.frontendVersion) |
| Integrity | Currently MD5 only (FlutterPatcher.init(strictSignature: false)); Ed25519 can be added later |
Core model: baseline-free + auto-publish + compatibility key
- Baseline-free: the Bundle client fetches the latest backend Release of its channel — dev → rolling tag
dev; stable → GitHub/releases/latest(dev is a prerelease, so latest returns the newest stable). Resolved bylib/core/updater/channel_release_resolver.dart; any non-latest → latest. - Auto-publish:
build-and-release.yml'sbuild-androidjob runsdart run flutter_patcher:packon every release, producingpatch-<abi>-<commit>.zip+manifest-<abi>.jsonuploaded with the release (arm64-v8a/armeabi-v7a/x86_64). The manualpatch-release.ymlis gone. - Comparison: dev by git commit hash; stable by version number (semver,
lib/core/updater/version_compare.dart). Already-applied (flutter_patcher.currentVersion == patchLabel) is skipped. - Version code and engine compatibility — Gradle sets a minimum
versionCodeof 4002 for the universal APK so it can replace older split APKs, whose highest code was 4001. CI reads the actual code from the APK with aapt and writes it to every ABI-specific frontend patch and manifest. The client checks the version code, Flutter engine key (flutterBinding), and native contract. A version-code or engine mismatch requires a full APK.
Client flow (startup check + manual)
Entry: ShellLayout.initState calls PatchUpdateDialog.maybeShow once per session (lib/core/updater/) — the frontend patch (this doc) and backend patch (Bundle build) are merged into one dialog. The startup path is gated by a delay, a user toggle and a throttle; the manual entry lives under "Settings → About & updates → Check for client updates". See backend_hotupdate.md.
- A hot-patchable patch (and not "ignored") → a dismissible dialog listing pending components + a GitHub proxy selector (reusing
GithubProxySelectionMixin) + buttons [Ignore this version] [Later] [Download & update]; download shows progress → on success a "restart to apply" dialog ([Restart now] =EmbeddedBackendService.restartProcess(), a real process cold restart solibapp.sotakes effect on cold start). - No patch but a newer full version on the same channel (
FrontendVersionApi, not ignored) → "New version required" dialog → [Ignore] [Later] [Go to download]; go-to-download navigates to/settings(which has the client-update APK download). - Neither → silent.
- Proxy: both the manifest fetch and the patch download go through the selected proxy (
PatchUpdateService.applyProxy, prefix concat); the choice persists togithubProxyProvider, shared with the plugin store / full-package upgrade. - Ignore: remembered separately in
AppPreferences.ignoredPatchVersion / ignoredClientVersion.
Hosting & URL convention
Patches are uploaded to the corresponding channel Release. Standard uses manifest-<abi>.json / patch-* in the Flutter client Release. Bundle uses bundle-flutter-version.json / bundle-patch-* in the backend Release. The client selects assets by HAS_BACKEND and channel.
- Standard manifest:
https://github.com/songloft-org/songloft-player-flutter/releases/download/<tag>/manifest-<abi>.json; Bundle usesbundle-flutter-version.json.- stable:
<tag>=v<version>(resolved via/releases/latest); dev:<tag>=dev - Bundle content is
{"hasUpdate":true,"patches":{"<abi>":{"version","semanticVersion","gitCommit","flutterBinding","targetVersionCode","patchUrl","md5"}}}. Standard content uses onepatchobject.
- stable:
- Patch package:
patch-<abi>-<commit>.zipfor standard andbundle-patch-<abi>-<commit>.zipfor Bundle (md5 over the zip) - Backward compatibility: when a legacy manifest lacks
semanticVersion/gitCommit/flutterBinding, the client falls back to the old "hasUpdate+ versionCode binding + already-applied guard" behavior.
Publishing (build-and-release.yml's build-android, automatic)
The Flutter client Release publishes standard manifest-<abi>.json and patch-<abi>-<commit>.zip assets. The backend Release's Flutter Bundle job creates bundle-flutter-version.json, bundle-patch-<abi>-<commit>.zip, and the backend manifests from one Bundle APK.
Release discipline
- Dart-only change → ships with the next release automatically; old builds hot-update, effective on cold restart (no separate patch tag);
- Native / plugin-native / engine change → if the Flutter engine changes, the
flutterBindingkey mismatches and old builds auto-fall to the full-APK branch; a deliberate versionCode bump goes full APK the same way, and users are guided to download the APK. - Dart referencing native resources (
res/) is a hidden boundary crossing: strings likeandroidIcon: 'drawable/xxx'in Dart are resource names nobody checks at compile time, and the native-contract hash gate can't catch them either (it only covers the MethodChannel surface) — yetres/stays frozen in the old APK. After a hot update, referencing a resource the old APK lacks makesgetIdentifier()return 0 and the native notification build throws. Only reference resources that have long shipped in historical APKs and whose content has no theme-attribute (?attr/...) dependency; a newly added resource requires a full APK. (songloft-org/songloft#329; statically backstopped bytest/core/audio/notification_icon_contract_test.dart)
Verification
flutter analyzepasses;flutter build apk --releasesucceeds.- Install an old dev / stable APK of some ABI on a real device.
- Ship an update (change one visible Dart thing) → open the app → "Update available" dialog lists the frontend component → pick proxy → download → restart → see the change = success.
- Incompatible path: a new build with an upgraded Flutter engine →
flutterBindingmismatch → opening the app shows "New version required" → navigates to/settings. - After "Ignore this version" the same version stops prompting; a higher version resumes prompting.
Notes
- Google Play and some channels may restrict dynamic delivery of executable
.so; this project targets self-controlled / sideload distribution. - flutter_patcher is beta; validate internally before staged rollout.
- Requirements (already met): AGP 8.11.1+ / Kotlin 2.2.20+ / Java 17 / minSdk 24 / compileSdk 36 / NDK 27+.
