Kotlin Multiplatform for AI Agents: Pros, Cons, and Release Pitfalls
Building two apps with Kotlin Multiplatform (KMP) over six months revealed key insights: code reuse across Android, iOS, Web, Desktop, and backend. The shared agent code integrated with libraries like koog, mcp-sdk, and cactus for local models. Hands-on experience highlighted the balance between the robust JVM ecosystem and platform-specific hurdles.
Key Advantages of KMP
KMP centralizes agent business logic, slashing duplication. The JVM ecosystem provides SDKs for LLM providers, while Compose Multiplatform streamlines UI with hot reload. Native Android builds leverage Skia for iOS, though Desktop relies on JAR wrappers.
Key benefits:
- Reuse platform-agnostic code across 4+ targets.
- Rich JVM ecosystem for agents and models.
- Stable Kotlin with backward compatibility.
- Compose with minimal UI glitches.
Clear Limitations
Multi-platform support demands expect/actual for platform-specific code. Desktop apps balloon due to JVM and Swing dependencies, Web is still beta with library bugs and SEO issues. iOS debugging feels basic, Swift interop lags behind JVM. Desktop UI often looks off-brand.
Hidden Development Challenges
macOS release builds take weeks: two app IDs (JRE and app), three signing keys, separate configs for app stores and DMG with notarization (15+ minutes per iteration). Native libraries complicate things—resources in JARs before signing, ProGuard exclusions, Catalina compatibility (63% of users). TestFlight needs JDK 18+, plus separate aarch64/x86_64 builds.
Typical release steps:
- Generate keys for stores and direct distribution.
- Embed native resources in JARs.
- Handle ProGuard obfuscation.
- Notarization and debugging (5+ iterations).
- Test on legacy macOS.
Lack of KMP senior experts: the job market favors single-platform devs. Platform-specific tasks (like iOS government certs vs. Android) demand deep expertise. LLMs struggle with edge cases.
Library Conflicts and Overengineering
Alpha libraries like kotlinx-datetime spark version clashes: koog pulls incompatible deps since September. Web lacks Dispatchers.IO, forcing branches in shared code. Offloading JVM logic for Android/Desktop/backend adds compile time but duplicates reflection.
Smart choices:
- JVM shared code: compromise on reflection.
- Loggers: balance logback and sensible defaults.
- Tests: mock Android context, add Desktop for speed.
Xcode worsens the pain: slow launches, laggy autocomplete, random crashes. Only 6.1% of Stack Overflow 2025 devs are willing to tolerate it.
Building AI Agents Without Frameworks
Ditched langchain4j (bloated, outdated) and koog (alpha, excess deps like simpleOpenAIExecutor). Custom implementation: node graph with transition callbacks, classification, RAG, error handling. Wins: full control, minimal deps, no OpenTelemetry bloat.
Agent graphs visualize for debugging, state machine persistence built manually for resilience. Testing targets shared code with platform mocks.
Testing Agent Code
Tests run on iOS/Android with context mocking. Desktop speeds up CI. Issues: long compiles, platform-dependent Dispatchers. Best practice: JVM unit tests, platform-specific integration tests.
Key takeaways:
- macOS releases demand weeks for keys, notarization, ProGuard.
- Alpha library version conflicts (kotlinx-datetime) break builds.
- Custom agents beat frameworks for niche LLMs (like GigaChat).
- KMP seniors are rare; platform skills essential.
- Xcode is an iOS dev bottleneck.
Overall verdict: KMP pays off for AI agents with JVM backends, but releases and iOS/Web need serious expertise.
— Editorial Team
No comments yet.