Chapter 2: Setting Up RevenueCat
Setting up in-app purchases from scratch means creating a Google Play Developer account, configuring your app in the Play Console, enabling the Google Play Developer API, setting up service account credentials, creating a Cloud Pub/Sub topic for RTDNs, and configuring billing permissions. That is a significant amount of infrastructure before writing a single line of client code.
RevenueCat setup has two parts: the RevenueCat dashboard (where you define your product structure) and the Android SDK (where you initialize the library). Most of the Play Console work still happens, you still need products and base plans there, but the server infrastructure you would otherwise build is replaced by RevenueCat's dashboard.
Step 1: Create a RevenueCat Account
Sign up at app.revenuecat.com. Create a project for your app. Within the project, add an Android app. RevenueCat will generate an API key for your Android app, you will need this key to initialize the SDK.
RevenueCat uses separate API keys per platform (Android, iOS, web). Use the Android-specific key in your Android app.
Step 2: Connect Google Play
In the RevenueCat dashboard, go to your app settings and connect your Google Play app. This requires:
- Package name: the same package name as in your Play Console app.
- Service account credentials: a JSON key file from a Google Cloud service account with the Google Play Developer API enabled. RevenueCat uses this to verify receipts and read subscription state.
The service account setup is the same as described in the raw billing handbook. RevenueCat needs a service account with the Financial data viewer permission in your Play Console. Once connected, RevenueCat polls the Play Developer API on your behalf, you never call it directly.
Step 3: Create Entitlements
In the RevenueCat dashboard under Entitlements, create the access levels your app grants. For example:
- Identifier:
pro_access - Description: Premium features including all themes and weather history
Entitlements are the logical access levels that drive your app's feature gates. You define them once here and check customerInfo.entitlements["pro_access"]?.isActive everywhere in your code.
Step 4: Import Products
Go to Products in the dashboard. Click Import to pull in your Google Play products. RevenueCat fetches the product catalog using the connected service account credentials. Select the products you want to manage with RevenueCat.
Attach each product to an entitlement. This tells RevenueCat: "when a user purchases this product, grant them the pro_access entitlement."
Step 5: Create Offerings
Go to Offerings and create at least one Offering. An Offering groups Packages. Add Packages to your Offering:
- Select a package type (Monthly, Annual, Lifetime, or custom)
- Assign a product to each package
Set one Offering as the Current Offering. Your app will fetch offerings.current to display the default paywall. You can change which Offering is current from the dashboard at any time, with no app update needed.
Step 6: Add the SDK Dependency
Add the RevenueCat SDK to your app's build.gradle.kts:
The SDK includes com.android.billingclient:billing as a transitive dependency. You do not need to add the BillingClient dependency separately. Do not add a conflicting BillingClient version, let RevenueCat control which BillingClient version it uses internally.
Step 7: Initialize the SDK
Initialize RevenueCat in your Application.onCreate(). This must happen before any other SDK calls:
If you pass null for appUserID, RevenueCat generates an anonymous ID for the user. If you have your own user authentication system, pass the user's ID instead. See the "User Identification" section in Chapter 11 for how to log in, log out, and merge anonymous purchase history.
Step 8: Listen for CustomerInfo Updates
Set an UpdatedCustomerInfoListener to receive CustomerInfo whenever the SDK refreshes it:
This listener fires after purchases, restores, and SDK-initiated refreshes. It does not fire on every app launch, you should also call getCustomerInfo() on launch to get the current state.
What You Do Not Set Up
Compared to raw billing, you do not set up:
- Cloud Pub/Sub topics or subscriptions
- RTDN push endpoint on your server
- Server-side receipt verification code
- Google Play Developer API integration on your backend
- Connection retry logic for
BillingClient
RevenueCat handles all of these. Your server only needs to receive RevenueCat webhooks if you want server-side events (covered in Chapter 10).