r/Kotlin • u/Willboy10538 • 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
2
u/mrbipbip13 11d ago
That Wasm GC fallback probe to
jsfor 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/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.