Menu

1 / 5

Ads in Kotlin Multiplatform: Shared Interface, Platform Shell

DEV Community: kotlin·Nesim Razon·10 days ago
#oKf7uZnn
#devtokotlin#devto#dev#interface#kotlin
Long article (1400 words) — no AI summary yet.
Reading 0:00
15s threshold

Ads are the part of a Kotlin Multiplatform app that cannot be shared, because the SDKs are native on each side. What can be shared is everything around them: when to show an ad, what happens if there is none, and what the screens are allowed to know. This is how my small Android and iOS apps split that work, with real names from the code.

One small interface in shared code

In Slinglings, the shared module has one interface named GameServices. The shared Compose screens know only this interface and nothing about AdMob. Its members fall into a few groups.

A global holder keeps the current implementation: Services.impl starts as NoServices, an object with no ads, where a rewarded request gives the reward immediately. The Android activity replaces it in onCreate with AndroidServices, which wraps AdMob, UMP, Play Billing and Firebase Analytics. One rule shapes every method: the callback always fires.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.