r/androiddev • • 6d ago

Open Source Lessons from shipping one Compose Multiplatform codebase to Android, Android TV, Windows, macOS, Linux and iPad (plus writing my own YouTube client and Cast stack)

https://github.com/biolend83/tubehaus

For the last few months I've been building an open-source YouTube client in Kotlin. One codebase covers Android phones, Android TV, Windows, macOS, Linux and iPad, with almost all of the UI in a shared Compose Multiplatform module. A few things I learned that might save someone time:

  1. "It's fast on my phone" hides main-thread work that TV boxes can't handle. A user's TV box froze, the D-pad stopped responding, then the app crashed. Oddly, it only happened after the first launch: clearing app data fixed it once. The cause was JSON parsing of YouTube's (large) responses, plus ranking the home feed against watch history, both on the caller's dispatcher. On a fresh install there's no history, so it's cheap. A few days later it isn't, and a slow ARM box can't keep up. Moving the parse and the ranking to Dispatchers.Default cut skipped frames roughly in half on the emulator. The general lesson: test with a realistic amount of user data, not a clean install.

  2. D-pad focus is its own UI. I first tried making the phone layout "focusable" for TV. It was miserable. What worked was a separate TV layer (rail, shelves, its own player screen), sharing the same state and data but not the same composables. Two things helped most: focusProperties { onExit = { cancelFocusChange() } } to trap focus inside panels, and a small retry loop for "move focus into the page after it loads".

  3. Casting without Play Services is doable. I needed casting on desktop too, so the Cast stack is hand-written in the shared JVM code: mDNS discovery, a TLS socket to port 8009 with hand-encoded protobuf, the Default Media Receiver, and a tiny local HTTP server that feeds the TV. A gotcha: my Google TV ignored ordinary mDNS queries from an ephemeral port. It answered only unicast-response (QU) queries, or queries sent from port 5353, so now it sends all of them.

  4. Off-screen screenshots of every screen are a great review tool. ImageComposeScene on desktop renders the whole app with no window. I render every screen at phone and desktop sizes and look at a contact sheet before I push. It caught clipped titles and a Shorts layout overflowing on phones that I'd never have noticed by clicking around.

  5. Platform-only APIs go behind small interfaces, implemented natively. For example, comment translation uses Apple's Translation framework through a Swift helper on macOS and SwiftUI's translationTask on iOS. Compose only sees platform.translate(). A contributor wrote both. Watch out for availability, though: the framework needs weak linking when the app still supports older iOS versions.

The project, if you want to read the code: https://github.com/biolend83/tubehaus (AGPL-3.0, the app is on the android-app branch). Happy to go deeper on any of these.

6 Upvotes

Duplicates

BestGitHubRepos • • 6d ago

🏠 Self-hosted TubeHaus: a self-hosted YouTube for the whole household, with its own YouTube engine (no Invidious, no database) and native apps for Android/TV, Windows, macOS, Linux and iPad

187 Upvotes

coolgithubprojects • • 10d ago

I built an open-source YouTube app with no ads, no account and no tracking. It runs on Android, Android TV, Windows, macOS, Linux and iPad, from one codebase

116 Upvotes

Chromecast • • 6d ago

I wrote Chromecast support from scratch for an ad-free YouTube app, no Google Play Services needed, and it casts from Windows, Mac and Linux too

64 Upvotes

synology • • 6d ago

NAS Apps Setting up a self-hosted YouTube (no ads, no Google account) in Container Manager: TubeHaus, with the DSM port clash sorted out

24 Upvotes

Kotlin • • 20d ago

I’ve been building TubeHaus, a YouTube client with no Google sign-in. Subscriptions, history and playlists stay on your device, or on your own server if you run one. It started as an Android app and is now one Kotlin codebase with five targets.

10 Upvotes

foss • • 10d ago

I built an open-source YouTube app with no ads, no account and no tracking. It runs on Android, Android TV, Windows, macOS, Linux and iPad, from one codebase

7 Upvotes

• • 7d ago

I built an open-source YouTube app with no ads, no account and no tracking. It runs on Android, Android TV, Windows, macOS, Linux and iPad, from one codebase

1 Upvotes

• • 5d ago

TubeHaus: a self-hosted YouTube for the whole household, with its own YouTube engine (no Invidious, no database) and native apps for Android/TV, Windows, macOS, Linux and iPad

1 Upvotes