Purpl Docs
Get started
Add the Purpl Android modules and register the purchase configuration for the app.
Requirements
- Android 8.0 (API 26) or later
- A Kotlin Android project, plus Jetpack Compose when using purpl-ui
- Products and license testers registered in Play Console
Add the modules
Clone the Purpl-Android repository next to your app project and include it as a composite build in settings.gradle.kts. Add purpl for purchases and entitlements, and add purpl-ui when you also want the default Compose paywall. The Google Play Billing Library comes with purpl, so you do not need to add it separately.
git clone https://github.com/ineedtoint/Purpl-Android.gitincludeBuild("../Purpl-Android")dependencies {
implementation("sh.purpl:purpl:0.1.0")
implementation("sh.purpl:purpl-ui:0.1.0")
}Register purchase configuration
Define every product used by the app and the entitlements granted by each product, then configure Purchases once when the Application starts. Share the returned instance across the app UI.
import android.app.Application
import sh.purpl.*
val plusEntitlement = PurchaseEntitlement(identifier = "plus")
val plusProduct = PurchaseProduct(
productIdentifier = "time.plus",
entitlementIdentifiers = setOf(plusEntitlement.identifier)
)
val purchaseConfiguration = PurchaseConfiguration(
entitlements = listOf(plusEntitlement),
products = listOf(plusProduct)
)
class TimeApplication : Application() {
lateinit var purchases: Purchases
private set
override fun onCreate() {
super.onCreate()
purchases = Purchases.configure(
context = this,
configuration = PurchasesConfiguration(
purchaseConfiguration = purchaseConfiguration,
entitlementMode = EntitlementMode.GooglePlay,
googlePlayPublicKey = "YOUR_GOOGLE_PLAY_PUBLIC_KEY"
)
)
}
}Google Play mode verifies current purchases on the device with the Base64-encoded RSA public key from Play Console and the local product mappings, so it needs no Purpl account or server. Consumable products and external payments are not supported.