purchases-kmp

Introduction: RevenueCat SDK for Kotlin Multiplatform
More: Author   ReportBugs   
Tags:

The RevenueCat SDK for Kotlin Multiplatform. It wraps RevenueCat's Android and iOS SDKs and handles purchases, entitlements, and subscription status.

Maven Central License: MIT

Docs · Install guide · Changelog · Migration guide

Requirements

Requirement Minimum
Kotlin 2.3.20
Java 8
Android 6.0 (API level 23)
Android compile SDK API 35 (API 36 with purchases-kmp-either)
iOS 13.0
watchOS 7.0

purchases-kmp-ui (Paywalls and Customer Center) needs Android 7.0 (API level 24) and iOS 15.0 or later, and isn't available on watchOS.

Installation

Add the SDK from Maven Central with Gradle. In libs.versions.toml:

[versions]
purchases-kmp = "<latest version>"

[libraries]
purchases-core = { module = "com.revenuecat.purchases:purchases-kmp-core", version.ref = "purchases-kmp" }

Then add the dependency to commonMain in your module's build.gradle.kts:

kotlin {
    // ...
    sourceSets {
        // ...
        commonMain.dependencies {
            implementation(libs.purchases.core)
        }
    }
}

The SDK calls native iOS code through generated Kotlin bindings, so opt in to ExperimentalForeignApi in your iOS source sets:

kotlin {
    // ...
    sourceSets {
        // ...
        named { it.lowercase().startsWith("ios") }.configureEach {
            languageSettings {
                optIn("kotlinx.cinterop.ExperimentalForeignApi")
            }
        }
    }
}

The native iOS SDK is compiled into the library, so iOS needs no CocoaPods or Swift Package Manager dependency. Other setup:

  • iOS: some projects only compile with isStatic = true in the iOS targets' binaries.framework block. See Build static binaries for iOS targets.
  • Android: set your Activity's launchMode to standard or singleTop. Other modes can cancel a purchase when the user leaves your app to verify it. See Set the correct launchMode.
  • Amazon Appstore: add Android's purchases-store-amazon module to androidMain. Use the version of the Android purchases library that purchases-kmp-core depends on (Gradle's dependencies task shows it on your Android runtime classpath), not the purchases-kmp version. For Amazon builds, configure with your Amazon app's public API key and set store = Store.AMAZON. See the version 3 migration guide.

The SDK's own artifacts share the group com.revenuecat.purchases and the purchases-kmp version:

Package What it's for When you need it
purchases-kmp-core Purchases, entitlements, subscription status Always
purchases-kmp-ui Paywalls and Customer Center, on Android and iOS You show RevenueCat Paywalls or Customer Center. See the Paywalls install steps
purchases-kmp-either Suspend functions that return Arrow's Either You handle errors with Arrow. Raises the compile SDK floor to API 36
purchases-kmp-result Suspend functions that return kotlin.Result You handle errors with kotlin.Result

Quick start

Before you start, create a RevenueCat project, connect your store or start with the Test Store, and add an entitlement. See the Quickstart.

Configure the SDK once, early in your app's lifecycle. Pass the public API key for the current platform (for example through expect/actual), or the Test Store key while you test. Omit appUserId to have RevenueCat generate an anonymous ID.

import com.revenuecat.purchases.kmp.LogLevel
import com.revenuecat.purchases.kmp.Purchases
import com.revenuecat.purchases.kmp.configure

Purchases.logLevel = LogLevel.DEBUG
Purchases.configure(apiKey = "<google_or_apple_api_key>") {
    appUserId = "<app_user_id>"
}

Check whether the user has an active entitlement before you show a paywall:

Purchases.sharedInstance.getCustomerInfo(
  onError = { error -> /* Optional error handling */ },
  onSuccess = { customerInfo ->
    if (customerInfo.entitlements[<my_entitlement_identifier>]?.isActive == true) {
      // Grant user "pro" access
    }
  }
)

What's included

  • Paywalls: build single-screen or multi-step paywalls in the dashboard, change them without an app update, and show them with the Paywall composable on Android and iOS.
  • Customer Center: a self-service screen where users manage their subscriptions and restore purchases, on Android and iOS.
  • Placements: serve a different Offering at each paywall location in your app.
  • Test Store: test purchases before you set up App Store Connect or Google Play Console.
  • In-app currency: read the current Customer's in-app currency balances.
  • Redemption Links: unlock a web purchase in your app from a deep link.
  • iOS subscription offers: promotional offers, the offer code redemption sheet, and win-back offers.
  • Your own purchase code: set purchasesAreCompletedBy when your app completes purchases itself.
  • Trusted Entitlements: the SDK checks a signature on entitlement data so your app can detect tampered responses. It runs in informational mode by default: it reports the result and doesn't block access.
  • Ad Monetization: report ad impressions, clicks, and revenue next to subscription data. Kotlin Multiplatform has no AdMob adapter, so you send ad events through adTracker. On Apple platforms, ad tracking needs iOS 15 or watchOS 8 or later.

Documentation

  • Install guide: Gradle setup, iOS build settings, Android launchMode, and the AndroidX App Startup requirement.
  • Configure the SDK: API keys, debug logs, Test Store, and other configuration options.
  • Displaying paywalls: present a paywall from Compose Multiplatform with the Paywall composable.
  • Testing purchases: Test Store and sandbox testing.
  • Migration guide: changes in the current major version, including the Android compile SDK floor and Arrow 2 in purchases-kmp-either.
  • KobanKat migration guide: new Maven coordinates and package names for apps moving from KobanKat, the independent project this SDK started as.
  • Kotlin Multiplatform codelab: a step-by-step tutorial covering installation, purchases, entitlement checks, and a paywall screen.

Using an AI coding agent

Your agent's training data is likely older than the current version of this SDK. Point it at current sources:

  • llms.txt: an index of the docs. Add .md to any docs URL for a Markdown version.
  • RevenueCat MCP server: lets your agent read and change your RevenueCat project configuration.
  • AI Toolkit: installs RevenueCat skills and the MCP server in one step.
  • Releases: check the latest version before adding the dependency.

Getting help

Contributing

This repository is published from the main branch and release tags of RevenueCat's internal development repository. Issues are tracked here. Pull requests are welcome: a maintainer reviews them here and brings accepted changes into the internal repository, so they can't be merged directly.

License

MIT. See LICENSE.

Apps
About Me
GitHub: Trinea
Facebook: Dev Tools
AI Daily Digest