---
metadata:
  - name: generator
    content: Diplodoc Platform v5.50.3
alternate:
  - https://divkit.tech/docs/en/quickstart/KMP.md
  - https://divkit.tech/docs/ru/quickstart/KMP.md
---
> **Documentation Index:** Fetch the complete configuration index at https://divkit.tech/docs/en/llms.txt

# Kotlin Multiplatform (KMP)

DivKit provides a library for using in Kotlin Multiplatform applications for both iOS and Android platforms. The library is published in Maven Central inside group `com.yandex.divkit.multiplatform` and versioned in accordance with the versions of the main DivKit library.

## Usage

### 1) Gradle dependency

Add the library as a dependency of your shared module:

```kotlin
kotlin {
    sourceSets {
        commonMain.dependencies {
            implementation("com.yandex.divkit.multiplatform:divkit-multiplatform:<divkit-version>")
        }
    }
}
```

### 2) iOS: add the `DivKitKMP` CocoaPod

The iOS implementation relies on a small bridging pod `DivKitKMP` to correctly link Obj-C symbols. The module provides the `DivKitKMPView` class that automatically handles view sizing and layout updates. Add it to your iOS app `Podfile` and run `pod install` from the iOS app folder:

```ruby
platform :ios, '13.0'
use_frameworks!

target 'YourApp' do
  pod 'DivKitKMP'

  # Other pods if needed
end
```

### 3) Render DivKit card in Kotlin multiplatform

You can create DivKit scope using function `DivKit` and pass common `DivKitDependencies` in it from shared code. Inside this scope you can call `DivView` function to render JSON and call `setVariables` to set variables to global storage.

In common code:

```kotlin
DivKit(dependencies) {
    var greeting by variable(name = "greeting", value = "Hello, Username")
    Column(
        modifier = Modifier.padding(WindowInsets.safeDrawing.asPaddingValues()),
        horizontalAlignment = Alignment.CenterHorizontally
    ) {
        DivView(
            cardId = "Sample",
            jsonData = jsonString,
            modifier = Modifier.wrapContentSize()
        )
        Button(
            onClick = {
                greeting = "Hello, DivKit User"
            },
            content = {
                Text("Say \"Hello\"")
            }
        )
    }
}
```

Also you can setup some platform-specific dependencies in platform-specific code. For example:

In Android part:

```kotlin
val environment = DivKitEnvironment.Builder(baseContext = this)
    .imageLoaderFactory { ctx -> PicassoDivImageLoader(ctx) }
    .lifecycleOwner(this)
    .build()

setContent {
    inject(environment) {
        MainScreen()
    }
}
```

In the iOS part, the `makeDivView` method returns `DivKitKMPView`, which automatically handles:
- `intrinsicContentSize` and `sizeThatFits` for proper size determination
- Layout updates when bounds change
- Calling `onVisibleBoundsChanged` when the visible area changes

<!-- source: en/_includes/index/troubleshooting.md -->
## Learn more {#troubleshooting}

You can discuss topics of interest in the DivKit user community in Telegram: [https://t.me/divkit_community_en](https://t.me/divkit_community_en).



[DivKit Repository](https://github.com/divkit/divkit)
<!-- endsource: en/_includes/index/troubleshooting.md -->
