Kotlin Multiplatform

Add Fload's attribution to a Kotlin Multiplatform app, Compose Multiplatform included. There's no separate KMP package. You use the two native SDKs from each platform's own code, and pass the user id through your shared module.


What you need

  • iOS 15 or later, and Android minSdk 24 or later.
  • Your app's write key.

1. Android: add the SDK to your Android app

Follow steps 1 and 2 of the Android guide in your Android app module (often androidApp or composeApp). In short:

kotlin
// build.gradle.kts of the Android app module, with JitPack in settings.gradle.kts
dependencies {
    implementation("com.github.fload-ai:fload-attribution-android:1.0.2")
}
kotlin
class PocketBudgetApp : Application() {
    override fun onCreate() {
        super.onCreate()
        Fload.configure(this, key = "fload_pk_…")
    }
}

2. iOS: add the SDK to your iOS app target

The iOS SDK is a Swift package. Add it to the Xcode project in iosApp, not to the shared module. Follow step 1 of the SwiftUI guide, then start it in your App:

swift
import SwiftUI
import FloadAttribution

@main
struct iOSApp: App {
    init() {
        Fload.configure(key: "fload_pk_…")
    }

    var body: some Scene {
        WindowGroup { ContentView() }
    }
}

3. Pass the user id from shared code

Your login and RevenueCat code usually live in the shared module. Kotlin/Native can't call a Swift package, so give the shared module a one-method interface that each platform implements:

kotlin
// commonMain
interface InstallAttribution {
    fun setUserId(userId: String)
}

On Android, implement it with the Android SDK:

kotlin
// androidMain, or the Android app module
class AndroidInstallAttribution : InstallAttribution {
    override fun setUserId(userId: String) = Fload.setUserId(userId)
}

On iOS, the interface is a protocol you implement in Swift:

swift
// iosApp
import FloadAttribution

final class IosInstallAttribution: InstallAttribution {
    func setUserId(userId: String) {
        Fload.setUserId(userId)
    }
}

Hand each platform's object to your shared code, the same way you pass in other platform services. Then call setUserId from shared code with RevenueCat's app user id, once RevenueCat is configured and again after each login. configure stays in each app's startup code, as in steps 1 and 2.


4. Check and ship

Check each platform as its guide shows: iOS and Android. Then ship both apps, and fill in Privacy for both stores.

A full sample app, with this setup on both platforms: samples/kotlin-multiplatform.