Skip to content

Latest commit

 

History

History

google

README.md

OpenIAP Android

OpenIAP Google Logo

Android implementation of the OpenIAP specification using Google Play Billing.


Maven Central API Google Release CI License

Modern Android Kotlin library for in-app purchases using Google Play Billing Library v9.1.

Documentation

Visit openiap.dev for complete documentation, API reference, guides, and examples.

Features

  • Google Play Billing v9.1
  • Kotlin Coroutines
  • Type-safe API with sealed classes
  • Real-time purchase events
  • Thread-safe operations
  • Comprehensive error handling

Requirements

  • Minimum SDK: 23 (Android 6.0)
  • Compile SDK: 36
  • Google Play Billing: v9.1.0
  • Kotlin compiler (consumer): 2.1.20+

Installation

Add to your module's build.gradle.kts:

dependencies {
    implementation("io.github.hyochan.openiap:openiap-google:<version>")
}

Use the latest version from Maven Central or the badge above.

To ship to Meta Quest or Fire OS as well, apply the OpenIAP Gradle plugin in settings.gradle.kts and keep the dependency above. It links the Horizon or Amazon build for a debug build on a Quest or Fire device, and for any build that sets openiapStore:

// settings.gradle.kts
pluginManagement {
    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}
plugins {
    id("io.github.hyochan.openiap") version "<version>"
}

See Store Setup for the full rule.

Quick Start

import dev.hyo.openiap.store.OpenIapStore

class MainActivity : AppCompatActivity() {
    private lateinit var iapStore: OpenIapStore

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        iapStore = OpenIapStore(this)

        lifecycleScope.launch {
            // Initialize connection
            iapStore.initConnection()

            // Fetch products
            val products = iapStore.fetchProducts(
                ProductRequest(skus = listOf("premium_upgrade"))
            )
        }
    }
}

For detailed usage, see the documentation.

Sample App

Run the included sample app:

cd packages/google
./gradlew :Example:installPlayDebug

The store flavor comes from the task name, so installPlayDebug, installAmazonDebug, and installHorizonDebug each build against their own billing SDK.

Purchase verification

Set these in packages/google/local.properties (untracked) or pass them as Gradle properties:

Property Gradle property Purpose
iapkit.api.key IAPKIT_API_KEY openiap-kit_pk_ publishable key, never an sk_ key.
iapkit.base.url IAPKIT_BASE_URL Origin of a local IAPKit server; empty uses the host.
amazon.rvs.sandbox AMAZON_RVS_SANDBOX true for Amazon App Tester receipts.

iapkit.base.url is an origin, not the verify path. For Local (IAPKit) the key and the local server must target the same Convex deployment. An Android device on USB reaches the host through adb reverse: inspect adb -s "$ANDROID_SERIAL" reverse --list, reuse an exact tcp:3100 mapping when one exists, or create it with adb -s "$ANDROID_SERIAL" reverse --no-rebind tcp:3100 tcp:3100, then use http://127.0.0.1:3100. Debug builds permit cleartext to loopback only; release builds keep the platform default.

The purchase and subscription screens list verification in this order:

  1. None (Skip) — skip verification.
  2. Local (Device) — trust the store's own purchase state on the device.
  3. Local (IAPKit) — IAPKit provider routed to iapkit.base.url.
  4. IAPKit — hosted IAPKit; the local URL is deliberately omitted.

With both values configured, the example defaults to Local (IAPKit). With only the key, it defaults to hosted IAPKit; without a key, it defaults to None (Skip).

Sponsors

Meta        Amazon Developer

Thank you to Meta and Amazon Developer for supporting OpenIAP. View sponsorship options.

OpenCollective

We also recognize sponsors and backers through OpenCollective. The original react-native-iap collective now supports the broader OpenIAP ecosystem and is managed separately from the main sponsor program.

Sponsors: OpenCollective sponsors

Backers: OpenCollective backers

Become a sponsor | Become a backer

Past supporters

Supported the project before the OpenIAP sponsor program.

Nami      Courier

License

MIT License - see LICENSE for details.

Support