Building Lanyard, part 4: iOS vs Android, one app on two very different phones

Porting an on-device AI app from iPhone to Android. Bringing your own model, Keystore surprises, a hidden 3 MB download, and why sharing the Swift code didn't work.

Dan Fernández

· 6 min read

Part 4 of Building Lanyard.

Lanyard started as an iPhone app, and once the iOS beta was out we began an Android port. It had to be the same product with the same promise: everything is processed on the phone and nothing goes to our servers. Both versions are fully native, SwiftUI on iPhone and Jetpack Compose on Android. We looked at Kotlin Multiplatform, Flutter, React Native and Skip and passed on all of them, since an app this close to the hardware (microphone, on-device models, the Keychain) spends most of its time in platform code anyway.

“The same app” ended up meaning very different things on each phone.

The model

On iOS the language model comes with the OS. Apple’s Foundation Models framework gives you a model that’s already on the phone, runs in a separate process and costs your app nothing in download size or memory.

Android has no equivalent we could use. We looked hard at Gemini Nano and passed. Its context window was under 4K tokens, too small for a talk transcript. It couldn’t run in the background, which is where most of our processing happens. The system updates it on its own schedule, so our tests couldn’t pin a version. And its SDK reports usage to Google, which we couldn’t square with our promise.

So on Android we ship our own model, Gemma 4 E2B, running on LiteRT-LM inside the app. The download is about 3.3 GB, checked against a pinned SHA-256 hash, and it resumes if interrupted; Google Play caps an AI pack at 1.5 GB, so the model is split in two ahead of time. On iOS the model costs the app 0 bytes of memory, while on Android it’s a 2.6 GB file in your own process. Our iOS memory budget is 600 MB, every Android setup we tested went well past it, and Android got its own budget.

Prompts that worked for Apple’s model made Gemma write the template’s placeholders back as values (“BUDGET: empty”), so each model now has its own prompts, with one shared output grammar.

Speech recognition

iOS uses Apple’s new SpeechAnalyzer. Android’s built-in recognizer isn’t meant for long, continuous recording, so there we ship sherpa-onnx with NVIDIA’s Parakeet model.

We scored both on the same test recordings with the same scoring file, and Android came out ahead here. Parakeet’s average word error rate was 18%, against 35% for Apple on our set. The average hides how each one fails, though. On a couple of hard, noisy voices Parakeet collapsed completely (one empty transcript, one at 96% errors), where Apple got worse more gradually.

End to end the two apps came out level. Android gained on speech, and on the same transcripts Apple’s model beat Gemma, mostly at telling “I owe them” from “they owe me”.

Keychain and Keystore

On iPhone the master key is a Keychain item that never leaves the device and isn’t synced. On Android a non-exportable Keystore key (in StrongBox where there is one, otherwise the TEE) seals a random master secret kept in the app’s private storage.

The Keystore surprised us twice. It insists on random IVs, and our file format uses a fixed nonce per file, derived from a per-file salt, so that part of the crypto runs in software and the Keystore protects the key that matters. And on some phones an OS update or a factory quirk loses Keystore keys. Every event is encrypted, so losing the key means losing the data, which is crypto-shredding by accident. Android has a recovery screen for this that iOS doesn’t need.

A signature check that only failed on the phone

Lanyard checks Ed25519 signatures on a small config file, which on iOS is a few lines of CryptoKit. Our Android tests passed on the JVM, but on a real Android 16 phone every signature was refused, because the platform had no Ed25519 verifier for a key you import yourself. We now use Bouncy Castle’s low-level RFC 8032 code for that one check. JVM unit tests tell you what the JVM supports, and the phone can be a different matter.

The 3 MB download nobody asked for

We count every byte the app sends or receives, and with telemetry off Android still showed about 2.95 MB of traffic on a fresh start. Compose pulls in androidx.emoji2, and its startup initializer asks Play services to download an emoji font. Play services makes the request, so it never went through our network gate, but the bytes were billed to our app. Removing the initializer fixed it. iOS has nothing like it, but it’s worth looking for in any Android app that promises not to phone home.

Background work

iOS gives you background tasks and a few rules. Android gives you WorkManager and a lot more rules. Overnight processing waits for charging and idle. Since Android 12 a foreground service can’t be started from the background, so “Summarize now” is a foreground service the user starts. Recording a 75-minute talk needs a microphone foreground service and an ongoing notification, and Google Play asks for a demo video for each foreground service type you declare.

Billing and reinstalls

Both stores sell the same Event Pass, tied to the event’s ID. On iOS, StoreKit 2 can rebuild purchases from history. Play Billing 8 no longer returns that history, so we store the receipt first and then consume it. Play refunds anything you don’t acknowledge within three days, so that step can’t be allowed to fail quietly.

One gap is still open. On iOS the “you’ve used your free event” record lives in the Keychain and survives deleting the app; on Android it doesn’t survive an uninstall.

Why we didn’t share the Swift code

To avoid porting the rules twice, we tried running the same Swift code on Android with the Swift SDK for Android. The output was byte-identical wherever locale didn’t matter. But Locale.current was always en_001 and TimeZone.current was always GMT, NSDataDetector and word enumeration don’t exist there, and JNI’s “modified UTF-8” mangles emoji, so strings had to cross as raw bytes.

So the rules were ported to Kotlin by hand. The Swift code stayed as the reference: it generates golden files, and the Kotlin code has to match them exactly. More than 600 goldens regenerate byte-identical.

Even dates needed care. Apple, the JDK and Android’s ICU don’t agree on abbreviations (“Sep” or “Sept”), and Android’s ICU can change with a system update, so reports hard-code Apple’s names for each locale and both phones write the same report.

What the two apps share

They share a spec folder rather than code. It holds:

  • payload fixtures for every schema version;
  • the encoding rules (date format, UUID case, canonical JSON);
  • golden outputs for reports, cards, telemetry, backups and erasure;
  • the network allowlist, design tokens, accessibility IDs and the AI scoring file.

Each acceptance criterion has an ID, a parity table records its status on each platform, and a script fails the build when the two drift apart. A backup made on an iPhone restores on Android, and the other way round.

Testing and shipping

GitHub’s hosted macOS runners can’t run Android emulators (no nested virtualization), so ours run on Linux or on our own Macs, and an emulator running Gemma needs its own 6 GB virtual device.

TestFlight takes an upload and a review. A new personal Google Play account has to run a closed test with 12 testers for 14 days before it can go to production, while an organization account is exempt, so plan for that early.

Next: the security decisions behind Lanyard, and how we enforce them.

Working on something similar?

If this is close to a problem your team has, tell us about it.