---
id: "getting-started/installation/unity"
title: "Unity"
description: "What is RevenueCat?"
permalink: "/docs/getting-started/installation/unity"
slug: "unity"
version: "current"
original_source: "docs/getting-started/installation/unity.mdx"
---

> **AI agents:** This is the Markdown version of a RevenueCat documentation page. For the complete documentation index, see [llms.txt](https://www.revenuecat.com/docs/llms.txt).

## 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](https://www.revenuecat.com/blog/growth/where-does-revenuecat-fit-in-your-app) or you can [sign up free](https://app.revenuecat.com/signup) to start building.

## Installation

[![Release](https://img.shields.io/github/v/release/RevenueCat/purchases-unity)](https://github.com/RevenueCat/purchases-unity/releases)

We provide 2 ways to install our SDK: via Unity Package Manager (UPM) in the OpenUPM registry, or as a `.unitypackage`. Version 10 of the plugin requires Unity 2022.3.33 or later.

The plugin uses Unity's [External Dependency Manager](https://docs.unity3d.com/Packages/com.unity.external-dependency-manager@2.1/manual/index.html) to add the Android and iOS dependencies when building your project.

### Option 1 (recommended): Install using OpenUPM

1. 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:

![](https://www.revenuecat.com/docs_images/sdk/unity/openupm-settings.jpg)

2. Then, go to the Package Manager and from "My Registries", select the RevenueCat package and click on Install. Unity's External Dependency Manager is a dependency of the package and is installed automatically.

![](https://www.revenuecat.com/docs_images/sdk/unity/package-manager-revenuecat.jpg)

:::info[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](https://openupm.com/docs/getting-started.html) if you haven't already, then run `openupm add com.revenuecat.purchases-unity`. That should be it!
:::

:::warning[If using Unity IAP alongside RevenueCat]
If you're using `UnityIAP` alongside `RevenueCat`, you need to follow special instructions outlined below.
:::

### Option 2: Import the Purchases Unity package

Download the latest version of [**Purchases.unitypackage**](https://github.com/RevenueCat/purchases-unity/releases/latest/download/Purchases.unitypackage).

Now, import the downloaded unitypackage to your Unity project. On first import, if your project has no dependency manager, the plugin installs Unity's External Dependency Manager through the Package Manager. This needs an interactive Editor session with access to the Unity registry. You can also install it beforehand from **Window > Package Manager > Unity Registry**.

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.

:::info[Projects already using Google's EDM4U]
Google's [EDM4U](https://github.com/googlesamples/unity-jar-resolver) keeps working with the plugin, but it is deprecated.

- With the `.unitypackage`, the plugin does not install Unity's External Dependency Manager while EDM4U is present.
- With the Unity Package Manager or OpenUPM, Unity's External Dependency Manager is a dependency of the package, so both managers end up installed and the Editor asks which one to use. In batch mode there is no prompt and EDM4U stays active.

To migrate, see the [v10 migration guide](https://github.com/RevenueCat/purchases-unity/blob/main/migrations/v10-MIGRATION.md).
:::

### iOS dependency manager (CocoaPods or Swift Package Manager)

On iOS, the RevenueCat SDK's native dependencies can be installed through either CocoaPods or Swift Package Manager (SPM). Both are fully supported. SPM support is available starting with `purchases-unity` 9.1.0. It works with Unity's External Dependency Manager, or with EDM4U 1.2.187 or newer.

Because [CocoaPods is being deprecated](https://blog.cocoapods.org/CocoaPods-Specs-Repo/), we recommend Swift Package Manager. With EDM4U 1.2.187+ SPM is enabled by default. To enable it:

1. Open the iOS Resolver settings. With Unity's External Dependency Manager, go to **Edit → Project Settings → External Dependency Manager → iOS Resolver**. With EDM4U, go to **Assets → External Dependency Manager → iOS Resolver → Settings**.
2. Enable **Swift Package Manager Integration**.
3. With EDM4U, click **OK**.

When SPM is enabled, the next iOS build adds the RevenueCat dependencies as Swift Packages to the generated Xcode project. If you are migrating an existing project that previously used CocoaPods, the resolver also removes the matching entries from the `Podfile` automatically. Any other CocoaPods dependencies in your project continue to work as before — SPM and CocoaPods can coexist in the same iOS build. For step-by-step instructions, see [Migrate the Unity SDK from CocoaPods to Swift Package Manager](https://www.revenuecat.com/docs/sdk-guides/unity-cocoapods-to-spm-migration).

:::warning[Don't add the RevenueCat iOS SDK separately]

This SDK already includes the RevenueCat iOS SDK, and RevenueCatUI if you install the UI package. Don't add `purchases-ios` or `purchases-ios-spm` to your Xcode project. Adding it yourself can cause duplicate package errors or version conflicts; see [Duplicate RevenueCat Swift packages](https://www.revenuecat.com/docs/test-and-launch/debugging/duplicate-revenuecat-swift-packages).

To call RevenueCat APIs from your own native code, add `import RevenueCat` (or `import RevenueCatUI`) to your Swift files.

:::

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

![](https://www.revenuecat.com/docs_images/sdk/unity/purchases-behavior.png)

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

### Set the Target API Level (Android only)

The SDK requires your app to compile against Android API 35 or later. Unity compiles against the Target API Level, so set **Player Settings > Other Settings > Target API Level** to 35 or higher. This also raises `targetSdkVersion`, which opts your app into Android 15 behavior changes such as enforced edge-to-edge display.

### Set the correct launchMode (Android only)

Depending on your user's payment method, they may be asked by Google Play to verify their purchase in their (banking) app. This means they will have to background your app and go to another app to verify the purchase. If your Activity's `launchMode` is set to anything other than `standard` or `singleTop`, backgrounding your app can cause the purchase to get cancelled. To avoid this, set the `launchMode` of your Activity to `standard` or `singleTop` in your Android project's `AndroidManifest.xml` file:

**AndroidManifest.xml**

```xml
<activity 
    android:name="com.your.Activity"
    android:launchMode="standard" />  <!-- or singleTop -->
```

You can find Android's documentation on the various `launchMode` options [here](https://developer.android.com/guide/topics/manifest/activity-element#lmode).

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

```csharp
using System;
using System.Collections.Generic;
using UnityEngine;

public class PurchasesListener : Purchases.UpdatedCustomerInfoListener
{
    public override void CustomerInfoReceived(Purchases.CustomerInfo customerInfo)
    {
        // display new CustomerInfo
    }

    private void Start()
    {
        var purchases = GetComponent<Purchases>();
        purchases.SetDebugLogsEnabled(true);
        purchases.GetOfferings((offerings, error) =>
        {
            if (error != null)
            {
                // show error
            }
            else
            {
                // show offering
            }
        });
    }

    public void BeginPurchase(Purchases.Package package)
    {
        var purchases = GetComponent<Purchases>();
        purchases.PurchasePackage(package, (productIdentifier, customerInfo, userCancelled, error) =>
        {
            if (!userCancelled)
            {
                if (error != null)
                {
                    // show error
                }
                else
                {
                    // show updated Customer Info
                }
            }
            else
            {
                // user cancelled, don't show an error
            }
        });
    }

    void RestoreClicked()
    {
        var purchases = GetComponent<Purchases>();
        purchases.RestorePurchases((customerInfo, error) =>
        {
            if (error != null)
            {
                // show error
            }
            else
            {
                // show updated Customer Info
            }
        });
    }
}
```

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

```
-keep class com.revenuecat.** { *; }
```

## Installation with Unity IAP side by side

Starting with version 8.0.0, RevenueCat's Purchases Unity SDK is compatible with Unity IAP 5.0.0 and above.

:::info[Unity IAP 5.0.0+ required]
If you're using an older version of Unity IAP, you'll need to upgrade to Unity IAP 5.0.0 or later to use the current version of the Purchases Unity SDK.
:::

:::warning[Amazon Store Support]
Unity IAP 5 has removed support for the Amazon Appstore. **If you need to support Amazon purchases, we recommend using the latest Purchases Unity SDK (8.0.0+) and letting RevenueCat handle all purchases directly**.

Completing transactions with your own IAP code requires consistent configuration across all stores. If you complete purchases with your own IAP code for Amazon, you must also do so for Google Play. However:

- Unity IAP 4 supports Amazon but uses an older BillingClient
- Purchases Unity 4.16.0 (last version compatible with Amazon SDK 2.0.76) doesn't work with the newer Google Play BillingClient required for current Unity IAP versions
- Unity IAP 5 removed Amazon support entirely

This means you cannot simultaneously support both Google Play and Amazon when completing transactions with Unity IAP. The recommended approach is to use RevenueCat to handle all purchases for both stores.

If your app only supports Amazon (not Google Play) and you want to complete purchases with your own IAP code, you can use [Purchases Unity 4.16.0](https://github.com/RevenueCat/purchases-unity/releases/tag/4.16.0) with Unity IAP 4.
:::

### Troubleshooting "duplicated class" errors

If using RevenueCat alongside Unity IAP or other plugin that includes the Android BillingClient library, you may get 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`.

![](https://www.revenuecat.com/docs_images/sdk/unity/custom-main-gradle-template.png)

Modify the `mainTemplate.gradle` to include the following at the end of the dependencies block:

**Groovy**

```groovy
dependencies {
    ...
    
    // ** ADD THIS **
    configurations.all {
        exclude group: 'com.android.billingclient', module: 'billing'
    }
}
```

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

:::danger
The above instructions will also apply if using other plugin that includes the Android InAppBillingService class, or for some other reason you get an error regarding duplicated classes.
:::

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

![](https://www.revenuecat.com/docs_images/sdk/unity/unity-symlink-sources-unchecked.jpg)

### Completing Transactions with your own IAP Code

:::info[Not recommended for Amazon Store]
Due to compatibility issues with Unity IAP and Amazon SDK versions, we do not recommend completing transactions with Unity IAP for Amazon Store. See the [Amazon Store Support warning](#installation-with-unity-iap-side-by-side) above for details.
:::

#### For Google Play (can also be done programmatically, see Configuration section)

![](https://www.revenuecat.com/docs_images/sdk/unity/google-play-store.png)

#### For Amazon Store (can also be done programmatically, see Configuration section)

![](https://www.revenuecat.com/docs_images/sdk/unity/amazon-store.png)

:::warning[Important note regarding InAppBillingService (Android Unity only)]
If using RevenueCat alongside Unity IAP or other plugin that includes the Android InAppBillingService class, follow [these instructions](https://www.revenuecat.com/docs/getting-started/installation/unity#troubleshooting-duplicated-class-errors)
:::

:::danger[Important (Android only)]
On Android, RevenueCat **will not** consume or acknowledge any purchase if [you tell the SDK that your app will complete purchases](https://www.revenuecat.com/docs/migrating-to-revenuecat/sdk-or-not/finishing-transactions), so be sure your app is handling that. **Failure to do so will result in your purchases being refunded after 3 days.**
:::

## Next Steps

- Now that you've installed the Purchases SDK in your Unity app, get started [building with Purchases →](https://www.revenuecat.com/docs/getting-started/quickstart#2-initialize-and-configure-the-revenuecat-sdk)
