# Unity SDK

## Installation

### **Unity Package Manager**

From the Unity Package Manager window:

* Add Package from Git url

```html
https://github.com/Purchasely/Unity-Package.git
```

### API Key

From the Purchasely package window (Windows -> Purchasely):

* Set the API Key field to your Purchasely API Key

### External Dependencies Manager

A third party external package is necessary to handle external dependencies with Cocoapods for iOS and Gradle for Android

* Got to *Assets* → *Import package* → *Custom package*
* Find and add ***external-dependency-manager-latest.unitypackage*** from <https://github.com/googlesamples/unity-jar-resolver>

You can also use [Unity Package Manager](https://openupm.com/packages/com.google.external-dependency-manager/) to install it

### Troubleshoot

If you have difficulties building your Unity project with Purchasely Package, please make sure to follow all those steps and [External Dependency Manager](#external-dependencies-manager) is installed on your project

#### Resolve on build or automatically

In *Assets -> External Dependency Manager -> Android Resolver > Settings* make sure that **Resolution On Build** and/or Auto Resolution are checked as well as **patch gradleTemplate.properties**

![](https://2145676854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKuAJGBnHJWZbqzA4g8yO%2Fuploads%2Fip4LEFscDMca8MgovAY4%2FSCR-20240112-mnvn.png?alt=media\&token=80cc983e-036f-4afd-b780-f4f0271e3522)![](https://2145676854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKuAJGBnHJWZbqzA4g8yO%2Fuploads%2FRVitvFFXwbxY3zD5WWlT%2FSCR-20240112-mnni.png?alt=media\&token=9b4f558b-b23f-4dd7-9960-e1be95996105)

#### Add custom gradle files

To allow dependency manager to work properly, it may be required to add custom gradle files to your project. You can do that in a few clicks

*File -> Build Settings -> Android -> Player Settings -> Publishing Settings*

You need to check

* Custom Gradle Properties Template

If it is still not working, we suggest to check also the following

* Custom Main Gradle Template
* Custom Base Gradle Template

![](https://2145676854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKuAJGBnHJWZbqzA4g8yO%2Fuploads%2FuoPp5WgGCEiYshWb3KMt%2FSCR-20240112-mpkx.png?alt=media\&token=4769d3df-6c99-40db-af65-3f2865ab7c08)

#### Remove included AAR or APK

If you have a duplicate class issue, it may be due to AAR or APK included directly in your Project. Unity may add them directly, you can look in Project window and *Assets -> Plugin -> Android*\
If you have some `aar` files, mainly the ones starting with *androidx*, included there, you should remove them as Purchasely already integrate them and they are the ones causing this conflict error

#### Clean Build

After including or updating Purchasely Unity Package, you should do a **Clean Build** in *File -> Build Settings -> Android* to make sure that the latest Purchasely android dependencies are fetched by your project
