# Kotlin Multiplatform for BLE apps: what to share, what not
URL: https://alexmitrovic.com/blog/kotlin-multiplatform-ble
Last updated: 2026-11-29

> How to structure a BLE app with Kotlin Multiplatform: shared protocol and device state in commonMain, BluetoothGatt and CoreBluetooth underneath.

[iOS & KMP](https://alexmitrovic.com/blog#ios-kmp)

# Kotlin Multiplatform for BLE apps: what to share and what to keep native

How to structure a BLE app with Kotlin Multiplatform: shared protocol and device state in commonMain, BluetoothGatt and CoreBluetooth underneath.

By [Alex Mitrovic](https://alexmitrovic.com/about)Published 29 November 20263 min read

## On this page

1. [The split](https://alexmitrovic.com/blog/kotlin-multiplatform-ble#split)
2. [The seam: one small interface](https://alexmitrovic.com/blog/kotlin-multiplatform-ble#seam)
3. [The iOS side in practice](https://alexmitrovic.com/blog/kotlin-multiplatform-ble#ios)
4. [Library or your own?](https://alexmitrovic.com/blog/kotlin-multiplatform-ble#libraries)
5. [Testing the shared core without phones](https://alexmitrovic.com/blog/kotlin-multiplatform-ble#test)
6. [FAQ](https://alexmitrovic.com/blog/kotlin-multiplatform-ble#faq)
7. [Sources](https://alexmitrovic.com/blog/kotlin-multiplatform-ble#sources)

**Stuck on this in a real app?** I fix it on real phones, usually within a week.

[Book a free call](https://alexmitrovic.com/contact)

Short answer

In a Kotlin Multiplatform BLE app, share the parts that must behave the same on Android and iOS: the device protocol (framing, parsing, checksums, OTA chunking), the connection state machine, retry policy and device state, behind a small BleLink interface. Implement that interface natively on each platform over BluetoothGatt and CoreBluetooth, because their threading, pairing and background rules really differ.

## Key takeaways

- Share the protocol and the state machine; keep the Bluetooth API calls native.
- A small interface (connect, write, notifications, state) is the seam between shared and native code.
- The shared code can be tested with a fake link, without phones, on every commit.
- Expose StateFlows to SwiftUI with a Swift-friendly wrapper; plan Swift interop early.
- Libraries like Kable can cover the platform layer; writing it yourself is fine when you need full control.

I build BLE apps for both platforms on a shared Kotlin Multiplatform core, and I led a startup's rebuild from Flutter to KMP. The question I get most is “how much can you share?” For BLE apps the honest answer is: most of the logic, none of the radio.

## The split

Native UI on top, one shared core in the middle, each platform's Bluetooth API underneath.

| Layer | Where | Why
| UI | Native (Compose, SwiftUI) or Compose Multiplatform | A product choice; both work
| Device state, screens' view models | Shared | Both apps must show the same state for the same device
| Protocol: framing, parsing, CRCs, versions | Shared | Pure logic; bugs here are the costliest to fix twice
| OTA chunking, offsets, verification flow | Shared | Identical on both platforms by definition
| Connection state machine, retry policy | Shared | Same decisions; inputs mapped from each platform
| Operation queue | Shared on Android's terms | Android needs it; on iOS it's harmless
| Scanning, connecting, GATT calls | Native | BluetoothGatt and CoreBluetooth differ in threading, pairing and errors
| Background work, permissions | Native | Foreground services vs background modes and restoration

## The seam: one small interface

commonMain: the interface and a session that uses it

```
// commonMain
interface BleLink {
    val state: StateFlow<LinkState>                  // Disconnected, Connecting, Ready(mtu), Failed(reason)
    suspend fun connect(id: DeviceId)
    suspend fun disconnect()
    suspend fun write(char: CharId, bytes: ByteArray, withResponse: Boolean = false)
    suspend fun read(char: CharId): ByteArray
    fun notifications(char: CharId): Flow<ByteArray>
}

class DeviceSession(private val link: BleLink, private val protocol: Protocol) {
    val temperature: Flow<Celsius> =
        link.notifications(CharId.Temperature).map(protocol::parseTemperature)

    suspend fun setTarget(t: Celsius) =
        link.write(CharId.Setpoint, protocol.encodeSetpoint(t), withResponse = true)
}
```

Everything above the interface is shared and testable. Everything below is about thirty methods of platform code per side. On Android it's the familiar `BluetoothGatt` with a queue; on iOS it's a `CBCentralManagerDelegate` and `CBPeripheralDelegate`, written in Kotlin against the CoreBluetooth headers, or in Swift and passed in.

## The iOS side in practice

- **Delegates in Kotlin/Native** are classes extending `NSObject` and implementing the protocol. It works, but Swift reads more naturally to iOS developers. If an iOS team will own that layer, let them write it in Swift and implement the shared interface.
- **Threading:** give CoreBluetooth its own dispatch queue and turn delegate callbacks into channel sends or `CompletableDeferred` completions; don't touch shared state from the delegate thread directly.
- **State restoration** stays native: the restore identifier, `willRestoreState` and re-assigning delegates. See [state restoration](https://alexmitrovic.com/blog/corebluetooth-state-restoration).
- **Flows in Swift:** Kotlin `Flow` and `suspend` functions aren't idiomatic Swift out of the box. Tools such as SKIE or KMP-NativeCoroutines expose them as async sequences and async functions, which SwiftUI views can consume cleanly.

## Library or your own?

Kable (by JUUL Labs) is a Kotlin Multiplatform BLE library that covers the platform layer for Android, iOS and JavaScript with a coroutine API. It's a good default when your needs are standard. I write the layer directly when a project needs full control: unusual bonding flows, a custom DFU bootloader dance, or exact behavior on specific phones. Both approaches keep the same shared core above the seam.

## Testing the shared core without phones

The biggest practical win is testing. A `FakeBleLink` in `commonTest` can simulate the device: answer writes, push notifications, drop the connection at the worst moment. The protocol, the OTA resume logic and the reconnect policy get tested on every commit, on both platforms' behalf, in seconds. Real phones are still needed for the native layer; see [testing on real phones](https://alexmitrovic.com/blog/testing-ble-apps-on-real-phones).

commonTest: OTA resume, tested once for both platforms

```
@Test fun otaResumesAfterDrop() = runTest {
    val link = FakeBleLink(device = FakeOtaDevice(imageSize = 300_000))
    link.dropConnectionAt(bytes = 180_000)
    OtaRunner(link).run(image)
    assertEquals(300_000, link.device.received)   // finished, without starting over
    assertEquals(1, link.device.restarts)
}
```

Add a lesson from the Flutter-to-KMP rebuild or your own device's app, e.g. what you'd set up differently on day one.

## FAQ

### Can Kotlin Multiplatform access Bluetooth on iOS?

Yes. Kotlin/Native can call CoreBluetooth directly, or the iOS app can implement a shared Kotlin interface in Swift. Libraries such as Kable also wrap CoreBluetooth for KMP.

### Should the BLE layer be shared in a KMP app?

The logic should: protocol, OTA flow, state machine and retry policy. The calls to BluetoothGatt and CoreBluetooth should stay platform-specific behind a small interface, because the platforms behave differently in ways that matter.

### Is Kable production-ready?

Kable is widely used and actively maintained, and it's a reasonable default for KMP BLE apps with standard needs. Evaluate it against your device's bonding, OTA and background requirements before committing.

## Sources

- [Kotlin documentation: Kotlin Multiplatform](https://kotlinlang.org/docs/multiplatform.html)
- [JUUL Labs: Kable](https://github.com/JuulLabs/kable)
- [Touchlab: SKIE](https://skie.touchlab.co/)
- [Apple Developer: Core Bluetooth](https://developer.apple.com/documentation/corebluetooth)

**Written by Alex Mitrovic**, an Android and iOS developer who builds reliable apps for Bluetooth and IoT devices and tests every fix on real phones. If your app has this problem on phones you can't pin down, the [BLE reliability audit](https://alexmitrovic.com/services/ble-reliability-audit) finds out why in about a week. [About me](https://alexmitrovic.com/about) · [LinkedIn](https://www.linkedin.com/in/aleksmitro98/)

## Read next

[**Android****iOS****Same device** Expertise### Kotlin Multiplatform developerHire a Kotlin Multiplatform developer who led a Flutter-to-KMP rebuild and shares BLE and business logic between Android and iOS apps.](https://alexmitrovic.com/kotlin-multiplatform-developer)

[**Before****After****Same device** Case study### Flutter to Kotlin Multiplatform rebuildAs Mobile Tech Lead I led a startup's rebuild from Flutter to Kotlin Multiplatform and Compose Multiplatform: architecture, maps, permissions, APIs.](https://alexmitrovic.com/work/flutter-to-kotlin-multiplatform)

[Article### CoreBluetooth state restoration: keeping an iOS BLE app connected in the backgroundHow an iOS BLE app keeps working in the background: the bluetooth-central mode, pending connections and state restoration, with Swift code.](https://alexmitrovic.com/blog/corebluetooth-state-restoration)

## Seeing this in your own app?

Send me the phone models and what the logs say. On a short call I'll tell you where I'd look first.

[Book a free call](https://alexmitrovic.com/contact)

Free · NDA on request · reply within 1–2 working days
