0Pricing
Kotlin Multiplatform Academy · Lesson

Wrap a Native SDK Cleanly

Hide an iOS-only SDK behind expect/actual.

Wrap a Native SDK Cleanly is a free Kotlin Multiplatform Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Kotlin Multiplatform Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

The Native SDK Problem

Some features only ship as an iOS-only SDK, like a payment or analytics kit. You still want one shared API your whole app can call. 🎁

Define the Contract First

Start in commonMain with a tiny interface describing what you need, in your own words, not the vendor SDK terms.

interface Analytics {
  fun track(event: String)
}

expect the Shape

Declare an expect way to obtain that interface. commonMain promises an implementation exists without knowing how it is built per platform.

expect fun analytics(): Analytics

actual on iOS

In iosMain provide the actual that forwards to the native SDK. This is the only place the vendor framework is ever imported.

actual fun analytics(): Analytics = IosAnalytics()

Adapt, Do Not Expose

Your iOS class is an adapter: it translates your clean calls into the SDK calls. The rest of the app never sees the vendor types.

A Stub for Android

If the SDK is iOS-only, androidMain still needs an actual. Provide a no-op or an Android equivalent so the app compiles everywhere.

Speak Your Domain Language

Name methods after your app, not the SDK. track and identify read better than the vendor names, and they shield you from future renames.

Swap Vendors Without Pain

Because callers depend on your interface, replacing the SDK means rewriting one adapter. Shared code does not change at all. ✨

Easier Testing

A small interface is easy to fake. In tests you provide a fake Analytics and assert it was called, with no real SDK involved.

class FakeAnalytics : Analytics {
  val events = mutableListOf<String>()
}

Inject the Implementation

Hand the chosen actual to your code through Koin or a factory. Injection keeps construction in one spot and the rest decoupled.

One SDK, One Wrapper

Keep a single wrapper per native SDK. That boundary is where platform mess stays, leaving the rest of your shared code clean and portable.

Quick Check

A quick check on isolating an iOS-only SDK.

Recap: Wrap a Native SDK

You learned to define a clean shared interface, provide actuals per platform, and keep the vendor SDK behind one adapter you can swap or fake. 🎉

Frequently asked questions

Is the “Wrap a Native SDK Cleanly” lesson free?

Yes — the full text of “Wrap a Native SDK Cleanly” is free to read here on the web, and the Kotlin Multiplatform Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Kotlin Multiplatform Academy course, upgrade to CoddyKit PRO.

What will I learn in “Wrap a Native SDK Cleanly”?

Hide an iOS-only SDK behind expect/actual. You practise Kotlin Multiplatform Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Kotlin Multiplatform Academy?

No prior experience is required. Kotlin Multiplatform Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Wrap a Native SDK Cleanly” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Kotlin Multiplatform Academy lesson?

Yes. Every Kotlin Multiplatform Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Use Apple Frameworks from Kotlin
  2. Memory & ARC in Kotlin/Native
  3. cinterop with C Libraries
  4. Wrap a Native SDK Cleanly
← Back to Kotlin Multiplatform Academy