# What is RevenueCat?

RevenueCat provides a backend and a wrapper around StoreKit and Google Play Billing to make implementing in-app purchases and subscriptions easy. With our SDK, you can build and manage your app business on any platform without having to maintain IAP infrastructure. You can read more about [how RevenueCat fits into your app](🔗) or you can [sign up free](🔗) to start building.

# Installation

We provide 2 ways to install our SDK: via Unity Package Manager (UPM) in the OpenUPM registry, or as a `.unitypackage`.

## Install using OpenUPM

  1. First you need to import the [EDM4U](🔗) plugin into your project if you haven't already. This plugin will add all the Android and iOS dependencies automatically when building your project. To do this, you can:

    • Download the `external-dependency-manager-latest.unitypackage` file from the root of the [EDM4U](🔗) repo.

    • [Import](🔗) the downloaded `unitypackage` to your project.

  2. Then, you can add the OpenUPM scoped registry. To do this, go to your project's settings -> Package Manager, and add a new scoped registry with URL `https://package.openupm.com` and scopes: `com.openupm` and `com.revenuecat.purchases-unity`. It should look like this: 

  3. Then, go to the Package Manager and from "My Registries", select the RevenueCat package and click on Install. 

Using OpenUPM-CLI

If you prefer, you can also use OpenUPM-CLI to add the scoped registry and the package through the command line. To do that, install the [OpenUPM-CLI](🔗) if you haven't already, then run `openupm add com.revenuecat.purchases-unity`. That should be it!

If using UnityIAP alongside RevenueCat

If you're using `UnityIAP`, you will need to install our SDK through the `Purchases-UnityIAP.unitypackage` method below. We currently don't distribute that version through UPM.

## 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. If you're running `purchases-unity` v3.5.1 or later, also make sure that the `RevenueCatPostInstall` script is added, since it will set up `StoreKit` for iOS and prevent issues when uploading builds to App Store Connect in Unity 2020. 

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 in versions of purchases-unity < 2.3.0

If using the RevenueCat plugin older than 2.3.0 alongside Unity IAP or other plugin that includes the Android InAppBillingService class, or you are getting `Duplicate class com.android.vending.billing.IInAppBillingService` please update to the latest Unity SDK or see the [legacy install instructions](🔗)

## 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. 

## Link StoreKit (iOS only)

`StoreKit` should automatically be linked. If you run into any issues, add _StoreKit.framework_ to _Linked Frameworks and Libraries_ in Xcode.

## 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:



# Unity Editor

Running the Purchases SDK is unsupported in the Unity Editor at this time, and may result in `NullReferenceException: Object reference not set to an instance of an object` errors. Please build and run your app instead.

# Proguard rules

If you have enabled Minify in Unity, make sure to add these custom rules to your `Assets/Plugins/Android/proguard-user.txt` and enable the Custom Proguard File setting in Publishing Settings:



# Installation with Unity IAP side by side

## Purchases Unity 4.0.0+

RevenueCat's Purchases Unity SDK 4.0.0+


**side by side with Unity IAP 4.4.0+**

Download `Purchases.unityPackage` and install as normal. Skip the rest of the instructions in this page.

**side by side with Unity IAP 3.3.0 < 4.4.0**

Download `Purchases-UnityIAP.unityPackage` and install as normal. Skip the rest of the instructions in this page.




## Purchases Unity versions 3.0.0 < 4.0.0

RevenueCat's Purchases Unity SDK 3.x


Purchases Unity versions 3.0.0 < 4.0.0 are not compatible with Unity IAP. Please update to the latest version if you need compatibility with Unity IAP.

Unity IAP doesn't work with version 3.3.0<4.0.0 of the purchases plugin

Make sure to use version [3.2.0](🔗) of our plugin. Due to incompatibilities with the version of BillingClient used by Unity IAP, the latest versions of the plugin won't work alongside Unity IAP until Unity IAP gets updated to BillingClient 4.x.x.




## Troubleshooting "duplicated class" errors



Follow this instruction if using RevenueCat alongside Unity IAP 2.2.0+, other plugin that includes the Android InAppBillingService class, or for some other reason you get an error regarding duplicated classes.

If using RevenueCat alongside Unity IAP 2.2.0+ or other plugin that includes the Android BillingClient library you will be getting an error when compiling that warns about some BillingClient classes being duplicated.

The easiest way to remove the error would be to tell Gradle to not include the billingclient library that Unity IAP is already including.

In order to do that, 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` to include the following at the end of the dependencies block:



Perform a clean up of the resolved dependencies using the `Assets/External Dependency Manager/Android Resolver/Delete Resolved Libraries` menu. This will cleanup the previously downloaded .aars in `Assets/Plugins/Android`. Otherwise you could end up with duplicated classes errors.

Also make sure to perform a resolve, so External Dependency Manager adds the right dependencies to the generated `build.gradle`.

## Troubleshooting "ClassNotFoundException" errors at Runtime in Android

When exporting your project to Android, in the Build Settings window, make sure you uncheck the `Symlink Sources` checkbox. That will make it so Unity actually uses the correct source files for our SDK.



# Next Steps

  • Now that you've installed the Purchases SDK in your Unity app, get started [building with Purchases ](🔗)