CLAUDE LABJP
WWDC — WWDC 2026 confirms Siri runs on Google Gemini; third-party handoff to ChatGPT is dropped, and Siri AI won't ship in the EU under the DMA at iOS 27BILLING — 6 days until the Jun 15 change: Agent SDK, headless Claude Code, GitHub Actions, and third-party agents move to API-rate monthly creditOUTAGE — claude.ai, Claude Code, and Cowork saw an outage (Jun). Scheduled runs are safest when built around fallbackModel and retriesDYNAMIC-WORKFLOWS — Dynamic workflows are on by default on Max/Team and the API, for codebase-wide bug hunts and independent verificationULTRACODE — Claude Code's new ultracode setting sits in the effort menu, fixing effort to xhigh while Claude decides when to run a workflowOPUS4.8 — Claude Opus 4.8 is settled in as the default across major plans, with stronger coding, agentic, and reasoning skillsWWDC — WWDC 2026 confirms Siri runs on Google Gemini; third-party handoff to ChatGPT is dropped, and Siri AI won't ship in the EU under the DMA at iOS 27BILLING — 6 days until the Jun 15 change: Agent SDK, headless Claude Code, GitHub Actions, and third-party agents move to API-rate monthly creditOUTAGE — claude.ai, Claude Code, and Cowork saw an outage (Jun). Scheduled runs are safest when built around fallbackModel and retriesDYNAMIC-WORKFLOWS — Dynamic workflows are on by default on Max/Team and the API, for codebase-wide bug hunts and independent verificationULTRACODE — Claude Code's new ultracode setting sits in the effort menu, fixing effort to xhigh while Claude decides when to run a workflowOPUS4.8 — Claude Opus 4.8 is settled in as the default across major plans, with stronger coding, agentic, and reasoning skills
Articles/API & SDK
API & SDK/2026-04-14Advanced

Claude API × Kotlin Multiplatform — Building Production AI Features for iOS and Android

Integrating Claude API with Kotlin Multiplatform (KMP) to ship production-quality AI assistant features on iOS and Android. Streaming, error handling, retry strategies, and testing — written from a personal app developer's production experience.

kotlin-multiplatformkmpclaude-api71ios13android7mobile6aisdk7

Premium Article

The hardest part of Kotlin Multiplatform isn't writing shared code — it's accepting that the gap between "runs in commonMain" and "works properly on both platforms" is often wider than you'd expect. You can unify your networking with Ktor, but getting Claude API's streaming responses to flow correctly to your UI thread, with proper error handling and retry behaviour, takes careful design.

I have been working as an indie iOS and Android developer since 2014, mainly on wallpaper apps and relaxation/mindfulness apps. My titles together have crossed 50 million cumulative downloads, largely monetised through AdMob. For the past six months I have been integrating Claude API directly into those apps as an in-app assistant. Along the way I have repeatedly run into situations where iOS-only or Android-only code behaves subtly differently once it moves into a KMP project.

This article is the record of that work. It covers what I actually did to take Claude API from "runs in KMP" to "runs reliably for 24 hours in production alongside AdMob mediation," with the design decisions, pitfalls, and operational numbers I encountered as an indie developer. My goal is straightforward: to save you from getting stuck in the places where I got stuck.

Project Structure and Design Philosophy

Here's the recommended folder structure for Claude API integration in KMP:

shared/
├── src/
│   ├── commonMain/
│   │   └── kotlin/
│   │       └── com/example/ai/
│   │           ├── ClaudeClient.kt       # API client
│   │           ├── ClaudeModels.kt       # Request/response models
│   │           ├── StreamingHandler.kt   # Streaming logic
│   │           └── RetryPolicy.kt        # Retry and error handling
│   ├── androidMain/
│   │   └── kotlin/
│   │       └── com/example/ai/
│   │           └── PlatformClient.android.kt  # Android-specific
│   └── iosMain/
│       └── kotlin/
│           └── com/example/ai/
│               └── PlatformClient.ios.kt      # iOS-specific
androidApp/
iosApp/

Why this structure: Communication logic — request building, JSON parsing, and retry handling — has no platform differences, so it belongs entirely in commonMain. Only genuinely platform-specific concerns (SSL certificate pinning, Keychain/EncryptedSharedPreferences storage) go into androidMain and iosMain. This separation means bug fixes and features land in one place, not two.

Step 1: Gradle Configuration and Ktor Client

// shared/build.gradle.kts
plugins {
    kotlin("multiplatform")
    kotlin("plugin.serialization")
    id("com.android.library")
}
 
kotlin {
    androidTarget()
 
    listOf(
        iosX64(),
        iosArm64(),
        iosSimulatorArm64()
    ).forEach {
        it.binaries.framework {
            baseName = "shared"
        }
    }
 
    sourceSets {
        commonMain.dependencies {
            // Ktor — the KMP-native HTTP client
            implementation("io.ktor:ktor-client-core:3.1.2")
            implementation("io.ktor:ktor-client-content-negotiation:3.1.2")
            implementation("io.ktor:ktor-serialization-kotlinx-json:3.1.2")
            implementation("io.ktor:ktor-client-logging:3.1.2")
 
            // kotlinx.serialization — JSON parsing
            implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.8.0")
 
            // kotlinx.coroutines — async/flow
            implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.1")
        }
 
        androidMain.dependencies {
            // Android: OkHttp engine (connection pooling, HTTP/2)
            implementation("io.ktor:ktor-client-okhttp:3.1.2")
        }
 
        iosMain.dependencies {
            // iOS: Darwin engine wraps NSURLSession
            implementation("io.ktor:ktor-client-darwin:3.1.2")
        }
    }
}

Why OkHttp for Android and Darwin for iOS: OkHttp isn't available on iOS. The Darwin engine wraps NSURLSession, which integrates naturally with iOS-specific SSL and proxy settings. On Android, OkHttp's connection pool and HTTP/2 support are significant practical advantages for real devices on mobile networks.

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
Threading pitfalls in KMP × Claude API, surfaced through 12 years of indie iOS development and 50 million cumulative downloads
Operational knowledge not in the official docs: expect/actual signature alignment, SKIE / Swift Concurrency interop, GC tuning
A 14-item pre-release checklist covering API key protection, Crashlytics wiring, and behaviour on poor mobile networks
Secure payment via Stripe · Cancel anytime
Share

Thank You for Reading

Claude Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • Copy-paste ready implementation code
  • New advanced guides published daily
  • $5/mo or $10 for lifetime access
View Membership →

Related Articles

API & SDK2026-05-13
Design Decisions Every Indie Developer Faces When Integrating Claude API into Mobile Apps
A practical guide to the design decisions that indie mobile developers face when integrating Claude API — covering model selection, async UX patterns, context management, offline resilience, and cost control, drawn from 10+ years of personal app development experience.
API & SDK2026-05-02
Calling Claude API from iOS Shortcuts: A Personal Setup for Reshaping Selected Text on the Fly
A personal setup guide for invoking the Claude API directly from iOS Shortcuts. Reshape selected text in seconds with a Cloudflare Workers proxy that keeps your API key off the device.
Claude Code2026-04-07
Claude Code × Flutter: Complete App Development Guide — Accelerating Mobile Development with Dart and AI
A practical guide to using Claude Code for Flutter development. From auto-generating Dart code to state management, UI design, test automation, and App Store submission — a complete roadmap for indie developers.
📚RECOMMENDED BOOKS
Build a Large Language Model (From Scratch)
Sebastian Raschka
LLM Dev
Prompt Engineering for LLMs
Berryman & Ziegler
Prompting
AI Engineering
Chip Huyen
AI Eng
* Contains affiliate links
See all →