I built Minesweeper once — and it runs on Android, iOS, and Desktop 🚀
Same game.
Same UI.
Same business logic.
Powered by Kotlin Compose Multiplatform.
Why I built this
I wanted to go beyond demos and answer a real question:
Can Compose Multiplatform handle a state-heavy, logic-driven game across platforms?
So I rebuilt Minesweeper — fully playable on:
📱 Android
🍎 iOS
🖥️ Desktop (JVM)
From a single Kotlin codebase.
🧠 How I built it (Step-by-Step)
1️⃣ Shared Game Engine (Common Kotlin)
The core of the app lives in commonMain.
Grid modeled as List<List<Cell>>
Each Cell tracks:
isMine, isRevealed, isFlagged, minesAround
Mine placement deferred until first click
→ guarantees no first-move death
Flood-fill (BFS) reveals empty areas efficiently
Win condition checks after every move
👉 Result: 100% shared game logic
2️⃣ Clean Architecture (KMP-friendly)
I followed a clean separation:
Domain → Game rules & engine (pure Kotlin)
Data → User + high score persistence
UI → ViewModels + Compose UI
No Android or iOS code leaks into the domain.
3️⃣ Multiplatform Persistence
Each platform stores data differently, so I used multiplatform-settings.
Android → SharedPreferences
iOS → NSUserDefaults
Desktop → Java Preferences
Injected via DI, used from common code.
var highScore: Long
get() = settings.getLong("HIGH_SCORE", 0)
set(value) = settings.putLong("HIGH_SCORE", value)
4️⃣ Dependency Injection with Koin
Koin works beautifully with KMP.
Shared appModule for:
GameEngine
ViewModel
Repositories
Platform modules provide platform-specific dependencies
⚠️ iOS gotcha:
Koin must be initialized explicitly before Compose UI loads.
5️⃣ Compose Multiplatform UI (Write Once)
UI is written once using Compose:
- LazyVerticalGrid for the minefield
- StateFlow → UI reactivity
- Same Composables across platforms
Only the entry point changes:
- Android → Activity
- iOS → ComposeUIViewController
- Desktop → Window {}
🎯 What I learned
Compose Multiplatform is production-capable for complex state
Sharing UI + logic saved 60–70% dev time
KMP shines when logic is non-trivial (games, editors, tools)
iOS setup still needs care — but it’s getting better fast
🚀 Final takeaway
“Write once, run everywhere” is no longer a slogan.
With Kotlin + Compose Multiplatform, it’s becoming a real engineering advantage.
If you’re an Android dev curious about:
KMP in real apps
Compose beyond Android
Cross-platform architecture
👉 Save this post or comment “KMP” and I’ll share the repo & breakdowns.
Follow Akshay Nandwana for more Android & KMP insights 💚
Repost to help more devs learn 🚀
#Kotlin#ComposeMultiplatform#AndroidDev#KotlinMultiplatform#MobileEngineering#IndieDev