What is RevenueCat?
RevenueCat is an in-app subscription platform that makes it easy to build and manage IAPs on any platform. With the RevenueCat SDK, you can build and manage your app business on any platform without having to maintain purchase infrastructure. You can read more about how RevenueCat fits into your app or you can sign up free to start building.
Installation
1. Import the Purchases Unity package
Download the latest version of Purchases.unitypackage.
Import the downloaded unitypackage to your Unity project. Make sure the PlayServiceResolver
and the ExternalDependencyManager
folders are also added. These folders will install the EDM4U plugin, which will add all the Android and iOS dependencies automatically when building your project.


ExternalDependencyManager plugin
Make sure the ExternalDependencyManager is properly installed. Otherwise our plugin will not be able to compile. If you don't see the option under the Assets menu after restarting the editor, try reinstalling the RevenueCat plugin or manually importing the EDM4U plugin.
Android InAppBillingService
If using RevenueCat alongside Unity IAP or other plugin that includes the Android InAppBillingService class, or you are getting
Duplicate class com.android.vending.billing.IInAppBillingService
please follow this instructions
2. Create a GameObject with the Purchases behavior
The Purchases package will include a MonoBehavior called Purchases. This will be your access point to RevenueCat from inside Unity. It should be instantiated once and kept as a singleton. You can use properties to configure your API Key, app user ID (if you have one), and product identifiers you want to fetch.


The Purchases behavior is configured with your RevenueCat API key and the product identifiers you want to fetch.
3. On iOS, add StoreKit.framework to Linked Frameworks and Libraries in Xcode
4. Subclass Purchases.Listener MonoBehavior
The Purchases behavior takes one additional parameter, a GameObject with a Purchases.Listener component. This will be where you handle purchase events, and updated subscriber information from RevenueCat. Here is a simple example:
using System;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
public class PurchasesListener : Purchases.UpdatedPurchaserInfoListener
{
private void Start()
{
CreateButton("Restore Purchases", RestoreClicked, 100);
CreateButton("Do Other Stuff", DoOtherStuff, 300);
var purchases = GetComponent<Purchases>();
purchases.SetDebugLogsEnabled(true);
purchases.GetOfferings((offerings, error) =>
{
if (error != null)
{
LogError(error);
}
else
{
var package = offerings.Current.Monhtly;
if (package == null) continue;
var label = package.PackageType + " " + package.Product.priceString;
CreateButton(label, () => ButtonClicked(package), 500);
}
}
});
}
void ButtonClicked(Purchases.Package package)
{
Purchases purchases = GetComponent<Purchases>();
purchases.PurchasePackage(package, (productIdentifier, purchaserInfo, userCancelled, error) =>
{
if (!userCancelled)
{
if (error != null)
{
LogError(error);
}
else
{
DisplayPurchaserInfo(purchaserInfo);
}
} else
{
Debug.Log("Subtester: User cancelled, don't show an error");
}
});
}
void DoOtherStuff()
{
var purchases = GetComponent<Purchases>();
var data = new AdjustData
{
adid = "test",
network = "network",
adgroup = "adgroup",
campaign = "campaign",
creative = "creative",
clickLabel = "clickLabel",
trackerName = "trackerName",
trackerToken = "trackerToken"
};
purchases.AddAttributionData(JsonUtility.ToJson(data), Purchases.AttributionNetwork.ADJUST);
purchases.GetPurchaserInfo((info, error) =>
{
Debug.Log("purchaser info " + info.ActiveSubscriptions);
if (error != null) {
LogError(error);
}
});
Debug.Log("user ID " + purchases.GetAppUserId());
}
void RestoreClicked()
{
var purchases = GetComponent<Purchases>();
purchases.RestoreTransactions((purchaserInfo, error) =>
{
if (error != null)
{
LogError(error);
}
else
{
DisplayPurchaserInfo(purchaserInfo);
}
});
}
public override void PurchaserInfoReceived(Purchases.PurchaserInfo purchaserInfo)
{
DisplayPurchaserInfo(purchaserInfo);
}
private void logError(Purchases.Error error)
{
Debug.Log("Subtester: " + JsonUtility.ToJson(error));
}
private void DisplayPurchaserInfo(Purchases.PurchaserInfo purchaserInfo)
{
// Show purchaser info on screen
}
}
Installation with Unity IAP side by side
Follow this instruction if using RevenueCat alongside Unity IAP, other plugin that includes the Android InAppBillingService class, or for some other reason you get an error similar to:
Duplicate class com.android.vending.billing.IInAppBillingService found in modules classes.jar (:GoogleAIDL:) and classes.jar (com.android.billingclient:billing:2.0.3)
If using RevenueCat alongside Unity IAP or other plugin that includes the Android InAppBillingService class you will be getting an error when compiling that warns about IInAppBillingService being duplicated.
Download the Purchases_NoInAppBillingService.unitypackage version of the package. This version doesn't include the PlayServiceResolver
plugin and uses a modified version of BillingClient that doesn't include the IInAppBillingService.
Make sure you have custom Main Gradle Template selected in the Android Player Settings... That should create a mainTemplate.gradle
inside the Assets/Plugins/Android
.


Modify the mainTemplate.gradle
dependencies block to look like the following:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
**DEPS**
// ** ADD THIS **
implementation ('com.revenuecat.purchases:purchases-hybrid-common:1.2.0') {
exclude group: 'com.android.billingclient', module: 'billing'
}
}
Next Steps
- Now that you've installed the Purchases SDK in your Unity app, get started building with Purchases
Updated 5 months ago