Stremio's Android apps are built strictly around live streaming. There is no native way to save movies, single episodes, or full seasons before a flight or commute, and even if you download a stream externally, your offline watch progress never syncs back to your Stremio account once you reconnect. Meanwhile, many community builds ship with upstream telemetry SDKs, rough portrait layouts, and no persistent search history.
I built Almio (com.almio.mobile) as a native Kotlin + Jetpack Compose Android fork of stremio-native/stremio-android to fix that workflow end to end: a full offline download engine supporting both Direct HTTP/Debrid links and BitTorrent via an embedded Rust JNI streaming server, offline playback with deferred watch-progress sync, persistent search history, portrait-safe progress UI, custom Almio branding, and a privacy-clean multi-ABI GitHub Releases pipeline.
1. Four-Layer System Architecture
Almio separates UI rendering, reactive view state, background download/sync orchestration, and Rust/C++ media internals into four distinct layers:
Data Flow End-to-End
- Downloading:
Compose UIdispatches a download intoMainViewModel, which queues it inDownloadQueueManager. Depending on the source, eitherHttpDownloadEnginestreams directly orTorrentDownloadEngineroutes the torrent through the local Ruststream-server(127.0.0.1:11470). Bytes land safely in.partfiles viaRandomAccessFile, whileAssetBundlersaves posters, backdrops, episode thumbnails, and external subtitles alongside the video andOfflineDatabase+OfflineDownloadServiceupdate the UI and foreground notification in real time. - Offline Playback & Reconnect Sync: When offline,
MainViewModelloadsOfflineMediaMetaEntity, bundled artwork, and local subtitles into ExoPlayer or MPV. Playback ticks persist to SQLite withneedsSync = true; the momentConnectivityManager.NetworkCallback.onAvailablefires,WatchProgressSyncManagerreplays positions back intoStremioCore(loadOfflinePlayer→playerTimeChanged→playerEndedat≥90%→syncLibrary).
2. Unified HTTP & BitTorrent Download Pipeline
Maintaining two separate resume loops, speed meters, free-space guards, and .part writers for HTTP vs BitTorrent invites subtle edge-case bugs. Instead, TorrentDownloadEngine translates a torrent's infoHash, fileIndex, and trackers into a selective localhost URL on the bundled Rust stream-server, attaches enginefs-prio: 1, and delegates byte streaming straight to HttpDownloadEngine with alwaysSendRange = true:
// File not found: projects/almio/TorrentDownloadEngine.ktDownstream, HttpDownloadEngine writes chunks through RandomAccessFile to a .part file, handles HTTP 416 Range Not Satisfiable edge cases (either finalizing an already-complete file or resetting cleanly to byte 0), validates MIME types so HTML error pages or HLS/M3U8 stubs never get saved as corrupt .mp4 files, and performs an atomic rename once complete:
// File not found: projects/almio/HttpDownloadEngine.kt3. Mutex-Guarded Queue & Smart Stream Selection
DownloadQueueManager guards queue scheduling with a Kotlin Mutex inside pumpQueue() and tracks running coroutines in a ConcurrentHashMap<String, Job>. Before replacing an existing download for the same videoId, enqueueDownload atomically cancels and join()s the active job (and deletes stale partial files if switching torrents). It also enforces Wi-Fi-only constraints, retries transient failures, auto-deletes watched episodes when enabled, and pre-downloads the next episode once playback reaches ≥85%:
// File not found: projects/almio/DownloadQueueManager.ktWhile active, OfflineDownloadService runs as an Android FOREGROUND_SERVICE_DATA_SYNC notification reporting live percentage, downloaded MB vs total, transfer speed, and ETA with Pause and Cancel actions. For Quick Download on series, stream ranking prioritizes verified positive seed counts (parseSeedCount(seeds) > 0) plus quality and torrent-family matching, whereas movies always open the stream picker in download mode so Quick Download never picks a dead magnet blindly.
4. Offline Playback & Deferred Watch-Progress Sync
When watching downloaded content without internet access, every progress update writes to SQLite (OfflineDatabase) flagged needsSync = true. Once WatchProgressSyncManager detects network restoration via ConnectivityManager.NetworkCallback, it iterates pending items, feeds them back through StremioCore (loadOfflinePlayer → playerTimeChanged → playerEnded at ≥90%), calls core.syncLibrary(), and triggers smart cleanup:
// File not found: projects/almio/WatchProgressSyncManager.kt5. Engineering Failures, Roadblocks & Pivots
Torrent Downloads Stuck Forever at 0 B (?download=1 Piece Starvation)
- Symptom: Individual torrent downloads stayed stuck on
"Connecting to peers…"at0 Bindefinitely. - Root cause: Appending
?download=1inbuildSelectiveTorrentDownloadUrltriggeredPlaybackIntent::DownloadFullinside the Ruststream-server, which immediately boosted every piece in the file to priority7simultaneously—starving piece#0that the sequential HTTPRangereader was blocked waiting on. - Pivot: Removed
?download=1sostream-serverusesPlaybackIntent::DirectInitial→DirectSequential(3-piece cold-start head prioritization followed by sequential streaming). Time to first bytes dropped to 251 ms.
Vertical Letter-by-Letter Text Wrapping (D\no\nw\nn...) in Jetpack Compose
- Symptom: Settings dropdown titles wrapped one character per line vertically in portrait orientation.
- Root cause: Inside a Compose
Row, unweighted children are measured beforeModifier.weight(1f)siblings. The unweighted right-hand valueBoxheld a ~40-character string with no max width, claiming nearly 100% of the row and crushing the leftColumn(Modifier.weight(1f)). - Pivot: Added
Modifier.widthIn(max = 140.dp)to the value container and tightened option labels.
Portrait-Mode Truncation of Download Progress (75% • Downlo...)
- Symptom: Percentage, downloaded megabytes, and speed looked great in landscape but truncated mid-word in portrait across
EpisodeRow,DetailSheet, andDownloadsScreen. - Pivot: Moved
EpisodeWatchedBadgeonto its own line below full-width 2-line progress text inEpisodeRow, gaveDetailLiquidActionButtona 2-linelabel+subLabelcompact layout, and raisedActiveDownloadCardandOfflineEpisodeRowsubtitles tomaxLines = 2.
GitHub Workflow Push Rejection & Submodule local.properties
- OAuth scope block: Pushing
.github/workflows/android-ci.ymlfailed with:
! [remote rejected] master -> master (refusing to allow an OAuth App to create or update workflow '.github/workflows/android-ci.yml' without 'workflow' scope)
Resolved via gh auth refresh -h github.com -s workflow and gh auth setup-git.
- Dirty submodule trap: Upstream committed
streamio-core-kotlin/stremio-core-kotlin/local.propertieswith a hardcoded Windows path; reverting it locally causedSDK location not found. SettingANDROID_HOMEin the shell environment (matchingubuntu-latestCI) kept builds green without dirtying the submodule.
6. Benchmarks, Device Testing & Multi-ABI CI/CD
Almio was installed and verified over ADB on a Samsung Galaxy S23 Ultra (SM_S918B, arm64-v8a), reaching 251 ms cold-start torrent first-byte latency in on-device logs (server_current.log). On memory, the embedded Rust stream-server targets ~50 MB RAM compared to ~200 MB+ for the traditional Node.js server.js runtime.
Debug vs R8 Release v1.0.0 APK Sizes
| ABI Split | Debug APK | Release v1.0.0 (R8 + Shrunk) | Exact Release Bytes |
|---|---|---|---|
arm64-v8a | 119.8 MB | 84.7 MB (~29% smaller) | 88,833,663 |
armeabi-v7a | 100.2 MB | 66.5 MB | 69,742,001 |
universal | 366.0 MB | 317.0 MB | 332,356,879 |
GitHub Actions (ubuntu-latest, run 45054422884) compiles Android CI in 6m 6s, and on tag push cross-compiles Rust stream-server + cold vcpkg OpenSSL in parallel across 4 ABIs (11m 59s–14m 15s) followed by R8 release packaging, PKCS12 signing, and SHA256SUMS.txt publishing in 5m 45s.
7. Privacy Cleanup & Open Source Release
All upstream Firebase/Crashlytics/Performance (google-services.json) and Facebook Login SDKs were stripped from the build, while the GitHub Releases in-app updater was made strictly opt-in via BuildConfig.UPDATE_GITHUB_REPO.
Almio is released under the GNU General Public License v3.0 (GPL-3.0) with a Section 7(e) trademark policy (TRADEMARK.md):
- Source Code: github.com/TheChos3nOne/Almio
- Downloads (
v1.0.0): Multi-ABI and universal signed APKs are available on GitHub Releases.
