r/Kotlin • • 11d ago

One Kotlin codebase on Android, iPhone, iPad and the browser: three things that caught me out

I have taken a small word game, WordEke, from an Android-only Kotlin and Jetpack Compose app to the same code running on Android, iPhone, iPad and the web (Kotlin 2.3.21, Compose Multiplatform 1.11.1). The game logic is a pure Kotlin module in commonMain and the UI is one Compose Multiplatform module. Three things were not in the tutorials.

1. Kotlin/Wasm does not run on older iPads. It needs WebAssembly garbage collection and exception handling, which Safari gained in 18.2, and every browser on an iPad is Safari underneath. iPads that stop at iPadOS 17 sat on "Loading" forever, with no error. I added a js target beside wasmJs, with the web code in a source set the two share, and the page now probes the browser and loads whichever build it can run. None of the web code had to change.

2. Fixed script names and long caching do not mix. My server caches .js for years. The generated script had a fixed name but referenced .wasm files named by content, so a deploy that replaced the folder left returning players holding a script that requested files that were gone. The scripts are now named by content too, and a deploy adds to the folder instead of replacing it.

3. A high iOS minimum hid a warning instead of fixing it. I had set the minimum to iOS 18.5 because it silenced a linker warning: Skia's ICU data object is built for 18.5. Dropping to 17.0 to reach those older iPads brought the warning back. It is data, not code, and everything passes on current simulators, but Xcode would not download an iOS 17 simulator for me, so the app is still untested on 17 itself. A refurbished 2018 iPad is on its way to settle it.

You can see the result at https://wordeke.com, where the browser version needs no install or account. Happy to go into detail on any of this, and I would like to hear from anyone with a cleaner way to serve Wasm with a JavaScript fallback.

Updates and feedback on the game itself: r/wordeke

5 Upvotes

6 comments sorted by

2

u/mrbipbip13 11d ago

That Wasm GC fallback probe to js for older Safari/iPadOS versions is super clean, way better than letting users sit on a silent hang. For the Skia/Xcode linker mismatch on iOS, pinning the Xcode version in CI or matching the CMP Skiko target usually clears those warnings up pretty fast.

1

u/mrbipbip13 11d ago

By the way, any chance this project goes open source, or that you could share the Gradle setup for those targets and their configurations?

1

u/Willboy10538 11d ago

No plans to open-source the whole thing for now (the word lists and the paid add-ons make that awkward), but happy to share the Gradle side. I've put the setup for all the targets in a gist: settings, version catalog, the two multiplatform modules (engine and Compose UI), the Xcode build phase and the task for each platform, plus the things that cost me time.

https://gist.github.com/10538/fe74dc0d07e86365dd8fe2304f95abb3

Short version: a `core` KMP module (jvm, iosArm64, iosSimulatorArm64, wasmJs, js) for the engine, a `shared` module with the whole Compose UI (android, iOS, wasmJs, js), and a plain Android `app` module on top. The two that caught me out were AGP 9 needing `com.android.kotlin.multiplatform.library` for the Android target, and `androidResources { enable = true }`, without which Compose resources quietly go missing from the APK.

1

u/mrbipbip13 8d ago

Awesome! Thanks for sharing!

1

u/ClassKlutzy7633 9d ago

On the caching point: one pattern that avoids the stale-loader problem is to keep the entry script small and serve it with Cache-Control: no-cache (revalidate each time), while the content-hashed .wasm/.js files get long immutable caching. Then returning players always fetch a fresh loader that points at files that exist, and you still keep the long cache where it's safe.

1

u/Willboy10538 8d ago

Thanks, that's good advice, and it's where I ended up after learning it the hard way. An early deploy replaced the whole folder, and an iPhone that had cached the old loader sat on "Loading WordEke…" for good, because the script it held pointed at .wasm files that no longer existed.

Now the page itself is the entry point. It's served with Cache-Control: no-cache and the little loader is inline in it, so a returning player always gets a fresh one. The game scripts and .wasm files are named by their content and cached for years, and deploys add to the folder rather than replace it, so a page from the previous build still finds its files.

The one thing I haven't done is add "immutable" to the long-cached files, which would save a revalidation on reload. I'll put that in at the next deploy. Thanks for taking the time to spell it out.