# Unity

{% hint style="info" %}
Hackle Unity SDK is built on top of Android SDK and iOS SDK. The following OS versions are supported.

* Android API 16 (4.1 Jelly Bean) and above
* iOS 10 and above
  {% endhint %}

{% hint style="danger" %}
Unity SDK does not support Desktop or Editor.
{% endhint %}

## SDK Installation

The SDK must be installed via Unity Package Manager.

Click [here](https://github.com/hackle-io/unity-sdk/raw/master/hackle-unity-sdk-1.9.1.unitypackage) to download the SDK.

In Unity, click `Assets > Import Package > Custom Package`.\
Select the downloaded package and import it to complete the installation.

![](/files/zWFq7yxVaCT55Du9Eqcq)

#### Android ProGuard / R8

If you are using ProGuard or R8, obfuscation rules are automatically included in the aar artifact. If that is not the case, you must include the following rules.

```
-keep class io.hackle.android.** { *; }
-keep class io.hackle.sdk.** { *; }
```

{% hint style="info" %}
Reinstall the app after SDK installation

Unity SDK includes Android and iOS SDKs.\
You must rebuild the app you were testing in order to complete the integration.
{% endhint %}

#### Notes on Updating

![](/files/5ARHgop9fefXcH5oeN2F)

When updating, you must delete the following selected libraries from the previously imported libraries before re-importing.

* hackle-android-sdk-x.x.x
* hackle-android-unity-wrapper-x.x.x
* hackle-sdk-common-x.x.x
* hackle-sdk-core-x.x.x
* ios-arm64\_armv7
* ios-arm64\_i386\_x86\_64-simulator

#### Android SDK Dependency Management

On Android, the following dependency libraries are required.\
If the Unity SDK does not work in an Android environment, verify that the following libraries exist.

* hackle-android-sdk-2.12.0
* hackle-android-unity-wrapper-1.5.0
* hackle-sdk-common-2.9.0
* hackle-sdk-core-2.9.0
* core-common
* gson
* kotlin-stdlib
* lifecycle-common
* lifecycle-extensions
* lifecycle-process
* lifecycle-runtime
* okhttp
* okio

## SDK Initialization

You must initialize `Hackle` before using the SDK. An SDK Key is required to initialize `Hackle`.

* `Hackle` is a class that provides methods for using the SDK features.
* Pass the **SDK Key** to the `Initialize()` method to initialize, and use `await` to wait until initialization is complete.
* You can find the SDK Key in [SDK Integration Info](https://dashboard.hackle.io/config/sdk-setting) on the Hackle Service Dashboard.

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

public class HackleInit : MonoBehaviour
{
    async void Awake () {
        await Hackle.Initialize(YOUR_APP_SDK_KEY);
    }
}
```

### SDK Initialization Config

You can initialize the SDK with configuration options included.

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

public class HackleInit : MonoBehaviour
{
    async void Awake () {
      HackleConfig config = new HackleConfig.Builder()
        .Build();
      await Hackle.Initialize("YOUR_APP_SDK_KEY", config: config);
    }
}
```

#### All Configuration Options

<table><thead><tr><th width="174.73828125">Config</th><th width="296.46484375">Description</th><th>Default</th><th width="108.28125">Supported Version</th></tr></thead><tbody><tr><td>ExposureEventDedupIntervalMillis<sup>*</sup></td><td>Removes duplicate exposure events for the same A/B Test or Feature Flag distribution result triggered consecutively by the same user.</td><td>60000 (1 minute)</td><td>1.7.0+</td></tr><tr><td>Debug</td><td>Outputs logs for all features to the console and sends events immediately.</td><td>false</td><td>1.7.0+</td></tr><tr><td>PollingIntervalMillis</td><td>Periodically updates settings configured in the Dashboard.<br>Min value: 60000 (60 seconds)</td><td>-1<br>(no periodic update)</td><td>1.7.0+</td></tr></tbody></table>

> <sup>\*</sup> Supported across app restarts from version 1.9.0 onward.

### Get Instance

After initialization, you can get the `Hackle` instance using the following code.

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

Hackle hackle = Hackle.GetInstance();
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.hackle.io/en/development-guide/unity.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
