Building a Cross-Platform App for Desktop, Android and iPhone: Lessons from Musix

By Eoin Villarin, 2026-10-07, updated 2026-10-28

What I learned shipping Musix, my open-source YouTube Music player, to Ubuntu, Windows, macOS, Android and iPhone: share the engine, design the contract first and plan for background audio.

What is the best way to build a cross-platform app for desktop, Android and iPhone?

The best way to build a cross-platform app with native-feeling interfaces is to share the engine and data, not the interface. Musix shares a TypeScript bridge, compiled filter data and design tokens across Ubuntu, Windows, macOS, Android and iPhone, while Electron, Kotlin with Jetpack Compose and Swift with SwiftUI each provide a native shell.

Key takeaways

  • Musix is a monorepo with three shared TypeScript packages, bridge, adblock and design, plus three native shells.
  • Every Musix bridge message is a versioned JSON object with a type, and every command carries a request ID.
  • On Android, Musix runs the WebView inside a Media3 MediaLibraryService with a custom player built on SimpleBasePlayer.
  • Each element the Musix bridge reads has an ordered list of fallback selectors to survive YouTube Music markup changes.
  • Musix's desktop app has 125 unit tests, 57 end-to-end tests, live site tests and a 60-minute soak test.

Building a cross-platform app usually starts with a framework decision: Electron, Flutter, React Native or Kotlin Multiplatform. When I built Musix, my open-source YouTube Music player for Ubuntu, Windows, macOS, Android and iPhone, the decision that mattered most was a different one: which part of the app to share, and which parts to let each platform do its own way.

Musix plays music through the official YouTube Music web player, with you signed in to your own Google account. It wraps that player in a native shell with media controls, lock screen integration, background playback, car screens and built-in ad and tracker blocking. It never downloads or extracts audio, and it is an independent project that is not affiliated with or endorsed by Google or YouTube.

This post covers the technical lessons from its first week, which brought six build targets and seven releases: the architecture, the bridge contract, background audio, testing against a page that changes without warning, and packaging.

What is Musix and why build it as a cross-platform app?

Musix began as a desktop player for Ubuntu. The goal grew into one player that looks and behaves the same everywhere while still respecting each platform: GNOME media controls on Ubuntu, notification and lock screen controls on Android, Now Playing on iPhone, and car screens through Android Auto and CarPlay.

The code is MIT licensed and public on GitHub, and the Musix case study has screenshots from every platform. The release history shows how quickly things move once the foundations are in place:

  • 1.0.0 (October 20, 2026): first release for Ubuntu, Windows, Android with Android Auto, and iPhone.
  • 1.0.1 to 1.0.3: fixed Google sign-in on every platform, smoother scrolling, and support for YouTube Music's new player bar.
  • 1.0.4: a native macOS build for Apple Silicon and Intel, and a matching look on Android.
  • 1.0.5 and 1.0.6 (October 25 and 26, 2026): playback reliability fixes, synced lyrics and search suggestions.

Lesson 1: share the engine, not the interface

The biggest decision was what not to share. Musix is a monorepo with three shared TypeScript packages and three native shells.

Car engine with belts and pulleys, a shared engine driving every platform
One shared engine, three native shells. Photo: rawpixel, CC0
  • shared/bridge is a script injected into the YouTube Music page that turns it into a typed playback engine.
  • shared/adblock is a build pipeline that compiles public filter lists into formats each platform can use natively.
  • shared/design holds design tokens, fonts and icons that are generated into CSS, Android resources and Swift.

Everything people touch, from the player bar to the settings screen, is native to its platform:

PlatformShellHosts the web player withNative integrations
Ubuntu, Windows, macOSElectron and TypeScriptWebContentsView in a frameless windowMPRIS media controls on Linux, tray icon, notifications, keyboard shortcuts
Android and Android AutomotiveKotlin and Jetpack ComposeAndroid WebViewMedia3 media session, notification and lock screen controls, Android Auto
iPhone and iPadSwift and SwiftUIWKWebViewNow Playing, lock screen, CarPlay templates, Siri media intents

On desktop, Electron's WebContentsView places the YouTube Music page inside the content area of a custom shell window, and the shell resizes it on every layout change. Sharing the engine gave every platform the same playback logic, parsing and filter data, while native interfaces meant I never fought a UI toolkit over lock screen controls or car templates. Share the layer that is genuinely identical everywhere, and nothing more.

Lesson 2: design the bridge contract before the platform code

The bridge is the heart of Musix, so its contract came first. Every message between the web page and the native app is a versioned JSON object with a type, and every command carries a request ID so the native side can match results and errors to the call that caused them. A trimmed excerpt:

export type BridgeCommand =
  | { v: 1; type: 'play'; requestId: string }
  | { v: 1; type: 'seekTo'; requestId: string; seconds: number }
  | { v: 1; type: 'setVolume'; requestId: string; volume: number }
  | { v: 1; type: 'search'; requestId: string; query: string; filter: SearchFilter };

export type BridgeEvent =
  | { v: 1; type: 'ready'; platform: Platform; clientVersion: string }
  | { v: 1; type: 'state'; state: BridgeState }
  | { v: 1; type: 'error'; code: BridgeErrorCode; message: string; requestId: string | null };

A few rules kept this contract stable across three languages:

  • One source of truth. The TypeScript types define the contract. Kotlin and Swift each have a small core module with a codec and a command queue that mirror it, covered by their own unit tests.
  • Validate at the boundary. The bridge rejects any command that fails validation and emits a typed error instead of guessing. It is the same mindset I describe in end-to-end validation with TypeScript and Zod.
  • A ready handshake. The bridge announces ready only once the player is usable. Earlier configuration commands are queued and everything else gets a not_ready error.
  • Contract tests with recorded fixtures. Real browse and search responses are saved as JSON fixtures, so a parser change that breaks the shape fails a test before it reaches a phone.

Strict TypeScript did a lot of quiet work here. With strict mode on and zero lint warnings allowed, contract drift shows up as compile errors, which is exactly where you want it. My TypeScript strict mode guide explains the settings I use.

Lesson 3: one bridge script, three native message channels

The bridge is bundled with esbuild into a single minified script and copied into the Android and iOS app bundles at build time, so every platform runs exactly the same code. What differs is how messages leave the page. A simplified version of how the bridge detects its host:

Turnstile gate with a card reader, checking each message before it passes through
Every message is checked on the native side before it runs. Photo: MTAPhotos, CC BY 2.0
export function detectTransport(win: Window): Transport {
  const host = win as unknown as HostWindow;
  if (typeof host.electronBridge?.send === 'function') {
    return { platform: 'electron', send: (json) => host.electronBridge!.send(json) };
  }
  if (typeof host.AndroidBridge?.receive === 'function') {
    return { platform: 'android', send: (json) => host.AndroidBridge!.receive(json) };
  }
  const handler = host.webkit?.messageHandlers?.ytm;
  if (typeof handler?.postMessage === 'function') {
    return { platform: 'ios', send: (json) => handler.postMessage(json) };
  }
  return { platform: 'none', send: () => undefined };
}

Each platform then receives those messages in its own safe way:

  • Electron: a preload script exposes a minimal API through contextBridge, renderers have no Node access, and the main process rejects IPC messages that come from the wrong sender or carry malformed payloads.
  • Android: the app uses WebViewCompat to register a web message listener limited to allowed origins and to inject scripts at document start. It falls back to a JavaScript interface only on WebView versions without those features.
  • iOS: scripts are added as WKUserScripts at document start in the main frame only, and messages arrive through a script message handler.

Keep the shared script unaware of the platform beyond one small adapter, and put the security checks on the native side, where the page cannot tamper with them.

Lesson 4: compile shared data once, emit native formats

Content filtering showed how far sharing should go. Each platform blocks requests differently, but all of them need the same underlying data: lists of ad and tracking hosts, URL rules and cosmetic selectors. So the adblock package does the hard work at build time. It downloads EasyList, EasyPrivacy and uBlock Origin's filter lists, parses them once, and writes platform-specific outputs:

  • Android gets hosts.bin, a compact binary file of sorted 64-bit FNV-1a hashes of blocked hostnames. A lookup is a binary search, so checking each request is fast and the file stays small.
  • iOS gets a JSON rule list in WebKit's content blocker format, capped at 150,000 rules and compiled on the device with WKContentRuleListStore.
  • Both mobile apps get cosmetic CSS and a small scriptlet bundle injected at document start.
  • Desktop uses the Ghostery adblocker engine, cached on disk and refreshed every 24 hours.

A manifest records a SHA-256 hash for every output. Design tokens follow the same pattern: one tokens.json file generates CSS variables, Android color and dimension resources, and Kotlin and Swift constants. On desktop, a test checks 16 foreground and background pairs per theme against the WCAG AA contrast ratio of 4.5:1, a topic I cover in my practical accessibility guide.

Share data and logic, then let each platform consume them in its native format. That is where shared code pays off without fighting the operating system.

Lesson 5: background playback is where platforms differ most

Playing audio with the screen off sounds like one feature. In practice it was three implementations and the source of most platform-specific bugs.

Headphones and a smartphone in low light, playing audio in the background
Background audio needed a different design on every platform. Photo: rawpixel, CC0

Android: wrap the web player in a Media3 player

On Android, the WebView runs inside a Media3 MediaLibraryService. A custom player built on SimpleBasePlayer translates Media3 calls such as play, pause and seek into bridge commands, and maps bridge state back into the player state that drives the notification, the lock screen controls and Android Auto. This follows the service-based approach in Android's background playback guide, and the app also manages audio focus and holds a wake lock during playback.

iPhone: configure the audio session properly

On iOS, the app declares the audio background mode and sets the AVAudioSession category to playback with the long-form audio policy. It listens for interruptions, route changes and media services resets, publishes track details to MPNowPlayingInfoCenter, and builds car screens from CarPlay's list and Now Playing templates. CarPlay audio apps also need Apple's CarPlay audio entitlement.

Linux desktop: speak D-Bus

On Ubuntu, GNOME's media controls and media keys talk to players over MPRIS on D-Bus. Musix publishes metadata and playback status there, with a fallback MPRIS service that starts if Chromium's own media session has not appeared within three seconds.

The bugs here were real. Version 1.0.5 fixed Android songs pausing right after they started, and 1.0.6 fixed the same symptom on iPhone and kept playback going with the screen off. On iPhone, a playback log under Settings now records every play, pause and stall with its cause, which turns vague reports into fixable bugs.

Lesson 6: assume the page you depend on will change

Musix depends on a web app it does not control, and YouTube Music changes its interface without notice. Version 1.0.3 exists because the player bar changed and Musix briefly showed "Nothing playing" while music played. Three habits limit that risk:

  • Selector fallbacks. Every element the bridge reads, such as the track title or the play button, has an ordered list of selectors, so a markup change falls through to the next match instead of breaking.
  • Diff before sending. The bridge compares each new state with the last one and only sends what changed, with progress updates throttled to four per second and a heartbeat every five seconds.
  • Tests at several levels. The desktop app has 125 unit tests, 57 end-to-end tests against a local fixture that reproduces the player markup, live tests against the real site and a 60-minute soak test.

The soak test was the most valuable. It plays continuously while navigating every 20 seconds, records heap size, DOM size and message rates, and asserts no more than 300 state messages per minute (the observed rate was about 233). That is how you catch listener leaks that only appear after an hour of real use.

Lesson 7: packaging and distribution are their own project

Building the app was half the work. Getting it onto every kind of device took the rest. A GitHub Actions workflow builds all targets for each release: an unsigned iOS IPA, the Android phone and car APKs, the Windows installer and portable build, the Ubuntu .deb and AppImage, and the macOS DMG and ZIP. A license check also fails the build if any shipped dependency uses a license outside MIT, MPL-2.0, Apache-2.0, BSD, ISC or OFL.

TargetPackagesDistribution detail to plan for
Ubuntu.deb and AppImageUbuntu 24.04 and newer restrict unprivileged user namespaces, so the .deb installs an AppArmor profile for the Chromium sandbox, and the AppImage needs FUSE 2
WindowsInstaller and portable .exeUnsigned builds show a SmartScreen warning on first run
macOSDMG and ZIPUnsigned apps need the quarantine attribute removed once in Terminal
AndroidPhone APK and Android Automotive APKSideloading needs installs allowed from that source, and Android Auto lists sideloaded apps only after enabling unknown sources in its developer settings
iPhoneIPASideloaded with a free Apple ID, so it must be reinstalled every 7 days

Code signing and store distribution are the obvious next steps. Until then, documenting every workaround step by step in the README was the honest answer.

Frequently asked questions

What is the best way to build a cross-platform app?

Start by deciding what is truly shared. If the interface must feel native on every platform, share the engine and data, such as business logic, parsing and generated assets, and build thin native shells around it. If the interface can be identical everywhere, a cross-platform UI framework saves time. Musix shares a TypeScript bridge, filter data and design tokens, and uses Electron, Kotlin and Swift for the interfaces.

Is Musix affiliated with YouTube or Google?

No. Musix is an independent open-source project and is not affiliated with or endorsed by Google or YouTube. It plays music through the official YouTube Music web player, and you sign in with your own Google account. It does not download, rip or extract audio streams, it uses no paid APIs or API keys, and the desktop app sends no telemetry.

Why use Electron for the desktop version instead of a native toolkit?

Musix hosts a web player, so the desktop shell needs a full browser engine anyway. Electron provides Chromium on Ubuntu, Windows and macOS from one codebase, with WebContentsView for embedding the player and mature APIs for trays, notifications and IPC. The cost is app size and memory use, which the soak tests monitor so regressions are caught early.

How do you test an app that depends on a third-party website?

Test in layers. Unit tests cover parsing, state diffing and validation. End-to-end tests run the real app against a local fixture that reproduces the site's markup, so they stay deterministic. A smaller set of live tests runs against the real site, and a long soak test catches memory leaks. Contract fixtures recorded from real responses catch parser breakage early.

What I would tell anyone starting a cross-platform app

The lessons from Musix apply well beyond music players. Share the layer that is genuinely identical, design the contract first, validate every message, generate native formats from one source, and test against reality for hours. Above all, budget real time for background behavior and distribution.

If you are planning a desktop app, a mobile wrapper or a web app that needs native features, I would be glad to help. Explore more of my projects in the case studies, or tell me about your app idea through the contact form.

Related reading