Skip to content

Kotlin Multiplatform

qa-kmp is a Kotlin Multiplatform facade over the cores. commonMain declares:

expect object Quameleon {
val isActive: Boolean
fun screen(name: String, route: String? = null)
fun track(name: String, props: Map<String, Any?> = emptyMap())
fun log(name: String, props: Map<String, Any?> = emptyMap())
fun probe(name: String, fn: () -> Any?)
}

The android and jvm targets share one actual over the pure-JVM QuameleonCore. The core is compileOnly, so the app provides it, from the qa-core sources (see Android) or from an adapter.

Start production mode or QA mode from the Android app exactly as in the Android quickstart, then call Quameleon.screen(...) and Quameleon.track(...) from shared code.

qa-kmp has iosArm64, iosSimulatorArm64 and iosX64 targets with no cinterop: the iOS actual forwards every call to a QuameleonBridge (an interface in iosMain) that your Swift app implements over the Swift core, so the Kotlin framework never links QuameleonQACore. Until a bridge is set, every call is a no-op.

import QuameleonQACore
import Shared // your KMP framework
final class SwiftQuameleonBridge: QuameleonBridge {
var isActive: Bool { QuameleonCore.shared.isActive }
func screen(name: String, route: String?) { QuameleonCore.shared.screen(name: name, route: route) }
func emit(kind: String, name: String, propsJson: String) { QuameleonCore.shared.emit(kind: kind, name: name, propsJson: propsJson) }
func setProbeHandler(handler: ((String, String) -> Void)?) { // closure type as your framework header declares it
QuameleonCore.shared.probeHandler = handler.map { h in { id, name in h(id, name) } }
}
func resolveProbe(id: String, valueJson: String?, error: String?) {
QuameleonCore.shared.resolveProbe(id: id, valueJson: valueJson, error: error)
}
}
// application(_:didFinishLaunchingWithOptions:), after QuameleonNative.start() (QA) or startProduction (production):
Quameleon.shared.bridge = SwiftQuameleonBridge()

Start QA or production mode from Swift as in the iOS quickstart; everything the shared code tracks then reaches the same core as the native code.

Terminal window
gradle jvmTest compileDebugKotlinAndroid iosSimulatorArm64Test

The JVM test activates the core and checks a tracked event and a probe reply over the real socket. The iOS test runs on a Simulator and checks that calls, typed props and probe replies reach the bridge.