DEV Community

Cover image for One Kotlin codebase for a kids' learning app on Android and iOS
TwoLogPI Apps
TwoLogPI Apps

Posted on Originally published at nibquest.com

One Kotlin codebase for a kids' learning app on Android and iOS

I make NibQuest on my own. It's a math and reading app for kids from Pre-K to 7th grade, with 330 skills, and it's on Google Play and the App Store. One person can't keep two copies of a curriculum in step, so almost everything is written once in Kotlin. Android runs it natively. iOS gets it as a framework built with Kotlin/Native, and Compose Multiplatform draws the screens on both.

This isn't a getting-started guide. JetBrains has good ones. It's the set of decisions that held up after two store launches, written down for anyone weighing the same setup.

Where the lines of code live

I counted on 21 November 2026, source only, tests and generated code left out.

Module What's in it Lines
shared/core Curriculum, question generators, mastery, reviews, learning records, save format about 52,200
shared/game App state, every screen and activity, drawing, animation, the grown-ups area about 13,600
android/platform Text-to-speech, audio, files, sharing, RevenueCat about 1,350
ios/platform The same jobs for iOS, written in Kotlin against Apple's APIs about 1,100
ios (Swift) The host app: launch, lifecycle, the view controller about 600

So roughly 95% is shared. Most of core is content, not logic. Each skill is a Kotlin definition with its questions, hints, mix-ups and standard codes. It's long, but it's dull to read, and that's how I want it.

Why the rules can't fork

A parent can move a child's progress from an Android tablet to an iPad. If the two apps disagreed by even one rule about when a skill counts as learned, the same file would show different checkmarks on each device. Parents notice that and stop trusting the app.

So the rules live in core, which has no idea which platform it's on. It depends on kotlinx.serialization and one bignum library, and nothing else. The save file is a serialized data class. Both apps read and write it with the same code.

Keep the platform seams small

Everything the shared code needs from the phone goes through a short list of expect declarations in shared/game:

expect fun createVoice(): Voice
expect fun createMusic(): Music
expect fun createSfx(): Sfx
expect fun createStore(): Store
expect object Billing { /* ... */ }
expect object Platform { /* ... */ }
Enter fullscreen mode Exit fullscreen mode

Voice, Music and the rest are ordinary interfaces. The Android actual wraps TextToSpeech and SoundPool. The iOS actual is also Kotlin, calling AVSpeechSynthesizer and AVFoundation through the platform bindings Kotlin/Native ships with. That's why there's so little Swift. I only write Swift where Xcode insists on it.

The rule I keep: a seam passes plain data and callbacks, never platform types. Voice.say() takes a list of lines with a speaker and some text. It doesn't know what an utterance object is. When a seam starts to want more, that usually means some logic is leaking into platform code and should move back into shared.

Decimals without Double

Fourth and fifth graders work with decimals, and the app checks their answers. A checker that thinks 0.1 + 0.2 is 0.30000000000000004 isn't usable. On the JVM I'd reach for BigDecimal, but common Kotlin doesn't have it.

So core has a small ExactDecimal class: a BigInteger plus a count of decimal places, built on com.ionspin.kotlin:bignum. Adding lines up the places first. Dividing reduces the fraction and then checks that the denominator has no prime factors other than 2 and 5. If it does, the answer would never terminate, and the class throws instead of rounding quietly:

while (b % TWO == ZERO) { b /= TWO; twos++ }
while (b % five == ZERO) { b /= five; fives++ }
if (b != ONE) throw ArithmeticException("Non-terminating decimal expansion")
Enter fullscreen mode Exit fullscreen mode

That throw is a feature. A question generator that would produce 1 ÷ 3 as a "decimal" problem fails a unit test, and never reaches a child.

Mastery as plain data

NibQuest counts a skill as learned after three answers given without a hint, and at most two of them can come on the same day. So every learned skill has been shown on at least two different days. Here's the whole rule:

@Serializable
data class TargetHits(val count: Int = 0, val day: Long = -1,
                      val today: Int = 0, val days: Int = 0) {
    fun tick(at: Long): TargetHits {
        val d = at / Mastery.DAY
        return when {
            d != day -> TargetHits(count + 1, d, 1, days + 1)
            today >= Mastery.TARGET_PER_DAY -> this
            else -> copy(count = count + 1, today = today + 1)
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Memory checks come back after 20 hours, then 3, 7, 21 and 60 days. A missed check reopens the skill. Alongside the counts there's a small Bayesian knowledge-tracing estimate. If the child asked for a hint before their first try, that answer doesn't move the estimate at all.

None of this touches a clock, a database or a screen. The time comes in as a parameter. That means the core tests run on the JVM in a few seconds, with no emulator or simulator, and they cover both platforms at once. There are 127 of them right now. They're the reason I can change a rule on a Saturday morning and ship it to both stores the same week.

Making a speech engine read math

Young kids can't read the instructions, so everything is read aloud with the voices already on the device. System speech engines are built for prose. Give one "3/4" and you might hear "three slash four", or a date.

So the shared Voice code rewrites text before any platform sees it. Fractions become words ("three quarters"), and emoji and other picture characters are stripped out so the engine doesn't read their names. Because this happens in shared code, a fix lands on both platforms at once. The only thing that differs between Android and iOS is which voices are installed.

What still bites

  • A crash I can't fix myself. On iOS, Compose Multiplatform 1.9.3 sometimes crashes during rotation inside its own layout code ("List is empty" from DepthSortedSet). It looks like JetBrains issue CMP-8935. I can reproduce it now and then on an iPad simulator, never on demand. The fix is a framework upgrade, so I'm waiting on that.
  • Tablets aren't "wide phones". My first tablet layouts keyed off the window width class. Big phones in landscape hit the expanded class too, and their layouts changed when they shouldn't have. Now every tablet branch checks the shortest side of the window (600dp or more), so a rotated phone stays a phone.
  • Not every screen is yours. On Android the plans screen is RevenueCat's hosted paywall. Its tablet layout lives in their dashboard, not in my code. On iOS that screen is my own Compose code. Two platforms, two places to make the same change.
  • iOS stack traces. A Kotlin exception on iOS shows up as a SIGABRT with a Kotlin trace buried underneath. While I was chasing the rotation crash, I added a temporary unhandled-exception hook just to print readable traces, then took it out again.

Would I do it this way again?

Yes. The cost is real: you still need a Mac and Xcode, Gradle builds for iOS are slow, and debugging on iOS is a step removed from the code. But the alternative was two curricula drifting apart, and for an app whose whole promise is "this checkmark means your child really knows it", that wasn't an option.

If you're building something similar, my one piece of advice is to put the rules that matter in a module that can't see the platform at all, and test that module hard. The UI sharing is nice. That module is what actually saves you time.

Happy to answer questions in the comments. If you want to see the app itself, it's at nibquest.com.

This post first appeared on nibquest.com.

Top comments (0)