Skip to content

Use AppeliumFeedback in a Kotlin Multiplatform app

A Kotlin Multiplatform app with native UI is a native iOS app and a native Android app that share Kotlin code. You add the AppeliumFeedback SDK of each platform, and bug reports, crash reports and the other features work as their guides describe. This page covers what the shared code needs in addition: Ktor requests, logs and errors from shared code, and readable Kotlin crashes on iOS. Read the limitations first if you are evaluating Appelium, or see the Kotlin Multiplatform overview for what your app gets and which plans include each feature.

The code on this page was tested with Kotlin 2.4 and Ktor 3.6.

Integrating with an AI coding agent?

Give Claude Code, GitHub Copilot or Cursor the prompt for this guide. It names the native packages, the Ktor OkHttp setup, the iOS crash hook and what to check afterwards.

Get the prompt

Add the SDKs

  1. Add and start the SDK in the iOS app, as in the iOS guide.
  2. Add and start the SDK in the Android app, as in the Android guide.

Each app uses the API key of its own application in the Dashboard. Call start before your shared code creates its Ktor client, or the client's requests can be missing on iOS.

Capture Ktor requests

On iOS, requests of Ktor's Darwin engine are captured without any code.

On Android, use Ktor's OkHttp engine and add Appelium's OkHttp integration (com.appelium:okhttp-v4, which works with both OkHttp 4 and OkHttp 5) to it. Add both SDK packages to the shared module:

androidMain.dependencies {
    implementation("io.ktor:ktor-client-okhttp:<ktor-version>")
    implementation("com.appelium:feedback:<feedback-version>")
    implementation("com.appelium:okhttp-v4:<okhttp-v4-version>")
}

Then configure the engine in androidMain:

import com.appelium.okhttp_v4.AppeliumOkhttpEventListener
import com.appelium.okhttp_v4.AppeliumOkhttpInterceptor
import io.ktor.client.HttpClient
import io.ktor.client.engine.okhttp.OkHttp

actual fun createHttpClient(): HttpClient = HttpClient(OkHttp) {
    engine {
        addInterceptor(AppeliumOkhttpInterceptor())
        config {
            eventListenerFactory(AppeliumOkhttpEventListener.Factory())
        }
    }
}

Network logs contain complete headers and bodies until you set an obfuscation handler, once in each app: iOS, Android.

Log and report errors from shared code

Declare what your shared code needs as an interface in commonMain:

interface Diagnostics {
    fun logInfo(message: String, domain: String)
    fun logError(message: String, domain: String)
    fun reportError(message: String)
    fun setUserIdentifier(userIdentifier: String?)
}

Implement it once for each platform, and pass the implementation to your shared code when the app launches:

import com.appelium.feedback.AppeliumFeedback
import com.appelium.feedback.e
import com.appelium.feedback.i

class AppeliumDiagnostics : Diagnostics {

    override fun logInfo(message: String, domain: String) {
        AppeliumFeedback.Log.i(message = message, tag = domain)
    }

    override fun logError(message: String, domain: String) {
        AppeliumFeedback.Log.e(message = message, tag = domain)
    }

    override fun reportError(message: String) {
        AppeliumFeedback.reportError(message = message)
    }

    override fun setUserIdentifier(userIdentifier: String?) {
        AppeliumFeedback.setUserIdentifier(userIdentifier = userIdentifier)
    }

}
import AppeliumFeedbackKit
import Shared // The framework of your shared module

final class AppeliumDiagnostics: Diagnostics {

    func logInfo(message: String, domain: String) {
        AppeliumFeedback.logInfo(message, domain: domain)
    }

    func logError(message: String, domain: String) {
        AppeliumFeedback.logError(message, domain: domain)
    }

    func reportError(message: String) {
        AppeliumFeedback.reportError(message)
    }

    func setUserIdentifier(userIdentifier: String?) {
        AppeliumFeedback.setUserIdentifier(userIdentifier)
    }

}

Report Kotlin crashes on iOS

On Android, an unhandled Kotlin exception is reported like any other crash. On iOS, it arrives as a SIGABRT without a message and without the function that threw it, unless you add a file named KotlinCrashReporter.kt with this code to iosMain:

import kotlin.experimental.ExperimentalNativeApi
import kotlinx.cinterop.ExperimentalForeignApi
import kotlinx.cinterop.UnsafeNumber
import kotlinx.cinterop.invoke
import platform.Foundation.NSException
import platform.Foundation.NSGetUncaughtExceptionHandler
import platform.Foundation.NSNumber
import platform.Foundation.numberWithUnsignedLongLong

@OptIn(ExperimentalNativeApi::class, ExperimentalForeignApi::class)
fun installKotlinCrashReporter() {
    setUnhandledExceptionHook { throwable ->
        NSGetUncaughtExceptionHandler()?.invoke(KotlinException(throwable))
        terminateWithUnhandledException(throwable)
    }
}

/** An Objective-C exception with the message and the stack trace of a Kotlin exception. */
@OptIn(ExperimentalNativeApi::class, UnsafeNumber::class)
private class KotlinException(throwable: Throwable) : NSException(name = "KotlinException", reason = throwable.toString(), userInfo = null) {

    private val addresses = throwable.getStackTraceAddresses().map { NSNumber.numberWithUnsignedLongLong(it.toULong()) }

    override fun callStackReturnAddresses(): List<NSNumber> = addresses

}

Call it in the iOS app, right after start:

AppeliumFeedback.start(
    apiKey: "YOUR_API_KEY",
    crashReporting: .enabled
)
KotlinCrashReporterKt.installKotlinCrashReporter()

The crash report then shows the class and message of the Kotlin exception, and its stack trace starts where the exception was thrown. Functions annotated with @Throws propagate their declared exceptions to Swift as Error values and do not trigger this hook; it handles uncaught Kotlin exceptions, including undeclared exceptions crossing into Swift and uncaught coroutine exceptions.

Upload symbols

Upload the symbols of each release as for a native app: the dSYMs of the iOS archive, which include those of your Kotlin code, and the mapping file of the Android build.

Record UI tests

Because the user interface is native, Appelium Tests works in the iOS and Android UI test targets as in any native app: iOS, Android.

Limitations

Area Details
Shared API There is no Appelium library for commonMain. Shared code calls the SDKs through an interface of your own.
Compose Multiplatform This guide is for apps with native UI. Apps that share their UI with Compose Multiplatform are not tested.
Kotlin crashes on iOS They are readable only with the code above. The report does not contain the exception's cause.
Unhandled exception hook on iOS Kotlin keeps one hook. If your app or a library already sets one with setUnhandledExceptionHook, combine the two.
Handled exceptions reportError sends a message without a stack trace, as in native apps.
Performance traces Start them in Swift and in Android code. On iOS, a trace name is a Swift string literal, so it cannot come from shared code.
Ktor engines Requests are captured with the Darwin engine on iOS and the OkHttp engine on Android. Other engines, such as CIO, are not captured.