← Back to the blog

One codebase, two stores: Einsatzlog in numbers

Every fire engine carries an equipment list – the Beladeliste. It says exactly what’s on board and where, and after every call someone checks it line by line. So, after release week, here is Einsatzlog’s equipment list: what’s shared, what’s platform-specific, and why.

The Beladeliste

I counted the Kotlin code in the app’s two modules (:composeApp and :ui) on the release line – non-blank lines, without comments and imports. The headless screenshot module isn’t included; it gets its own section below.

Compartment Lines What’s in it
commonMain 2,291 Every screen, every component, the theme, navigation, ViewModels, the Room database, the repository, suggestions, the PDF model, purchases
androidMain 125 Activity, Application, Koin platform module – and 93 lines of PDF drawing
iosMain 122 The UIViewController entry point, Koin platform module – and 87 lines of PDF drawing
Swift 28 iOSApp.swift and ContentView.swift. That’s the whole iOS project
commonTest 414 25 unit tests for the shared logic

That’s about 89 % shared – and the number undersells it. Take the PDF renderers out, and what’s left per platform is roughly 30 lines of glue: start the app, hand Koin the right implementations, report the version number.

The stack behind that: Kotlin 2.4, Compose Multiplatform 1.11, Room KMP with the bundled SQLite driver, Koin, Navigation Compose, kotlinx-datetime and RevenueCat’s purchases-kmp. All of it in commonMain.

Four expects, and why not more

expect/actual is Kotlin Multiplatform’s mechanism for “this exists, but every platform provides its own”. Einsatzlog has exactly four:

expect val platformModule: Module          // Koin: what each platform plugs in
expect val appVersionName: String          // shown in Settings
expect val revenueCatApiKey: String        // injected at build time, never in the repo
expect object AppDatabaseConstructor : RoomDatabaseConstructor<AppDatabase>   // required by Room KMP

Everything else that differs per platform goes through interfaces and dependency injection, not expect. The PDF export is the best example. Android draws with android.graphics.pdf.PdfDocument, iOS with CoreGraphics – two genuinely different APIs. But what goes on the page – header, entries, colours, page breaks – is computed once, in shared code, as a plain PdfExportModel. The platforms only draw it:

 commonMain                                       androidMain / iosMain
 ┌────────────────────────────────────┐           ┌────────────────────────────────────┐
 │ Einsatz + entries                  │           │ AndroidLogbookExporter             │
 │   ─▶ PdfExportModel (pages)        │──────────▶│   android.graphics.pdf.PdfDocument │
 │   ─▶ LogbookExporter (interface)   │  Koin     ├────────────────────────────────────┤
 │                                    │  binds    │ IosLogbookExporter                 │
 └────────────────────────────────────┘  one of ─▶│   UIKit PDF context · CoreGraphics │
                                                  └────────────────────────────────────┘
// AppModule.android.kt
single<LogbookExporter> { AndroidLogbookExporter(androidContext()) }
// AppModule.ios.kt
single<LogbookExporter> { IosLogbookExporter() }

The rule of thumb I ended up with: expect for values and things a library forces on you; interfaces for behaviour. Interfaces can be faked in commonTest; expect declarations can’t.

My store screenshots are rendered, not taken

Here’s the part I’m proudest of, and the one I’d most like other KMP developers to steal.

The :ui module has a third target next to Android and iOS: jvm(). It exists for one reason – so the real Compose screens can be rendered headlessly on a desktop JVM. A small module, :screenshots (about 270 lines), does exactly that:

 :ui  (the real screens, commonMain)
   │   jvm() target
   ▼
 :screenshots ── for device × language × theme × shot ──▶ off-screen Skia surface
                   5 sizes   de, en    light, dark   5       ─▶ PNG, exact store pixels
                                                              ─▶ build/store/play/…  (fastlane supply layout)
                                                              ─▶ build/store/appstore/…  (fastlane deliver layout)

One run writes 100 images: Google Play phone and 10-inch tablet, two iPhone sizes for the App Store, and the Devpost format – in German and English, light and dark. When App Review wanted 6.5-inch screenshots instead of 6.9-inch ones, the fix was one line: a new DeviceSpec.

The interesting bits are the traps:

// A 6.9" iPhone is 440×956 pt at @3x – rendering 440×956 dp at density 3 lands on exact store pixels.
SkikoComposeUiTest(width = spec.widthPx, height = spec.heightPx, density = Density(spec.density)).runTest {
    setContent(content)
    waitForIdle()                 // string resources load asynchronously – one raw frame can catch empty labels
    awt = captureToImage().toAwtImage()
}
  • Use the Compose test harness, not a bare ImageComposeScene. Compose resources load asynchronously; waitForIdle() is what makes the output deterministic.
  • The locale comes from the JVM. On desktop, Compose resources resolve against Locale.getDefault() – so that’s what picks German or English.
  • Pin the time zone. The app formats times in the device zone; a CI runner in UTC would print different clock times than a laptop in Berlin.
  • Strip the alpha channel. Both stores reject PNGs with transparency, so every image is composited onto an opaque, theme-coloured background.

The best side effect: the screenshots can’t lie. They are the app’s components, with demo data, at store resolution.

Open source, all of it

The whole app is open source under the MIT licence: github.com/Einsatzlog-Team/etb. That includes the parts that are useful beyond a fire-service logbook:

  • the headless screenshot renderer for Compose Multiplatform (screenshots/),
  • the atomic design structure of a shared Compose UI (ui/…/components/, explained in Atomic Design with Compose Multiplatform),
  • adaptive tablet layouts with window size classes from commonMain (branch feature/tablet-layout, explained in After the incident is before the incident),
  • RevenueCat with purchases-kmp, including build-time key injection so forks don’t need – or leak – keys (see Shipping week).

Fork it, copy the bits you need. If you build a logbook for your own brigade, I’d love to hear about it.

Things the numbers don’t show

  • I wrote most of it on Linux. The iOS target compiled the whole time, but the first real iPhone build still found a handful of bugs in a day. 89 % shared doesn’t mean 89 % tested on every platform.
  • The 28 lines of Swift still bit me – Kotlin’s initKoin() is exported to Swift as doInitKoin(), and SwiftUI and Compose both applied the safe area. Both one-liners, both in Shipping week.
  • Shared UI isn’t the same UI everywhere. Compose Multiplatform gives you the same components; it doesn’t make a phone layout good on a tablet. That still needed its own work.

Beladeliste checked. Everything’s on board.

#BuildInPublic