# 2. Install the Airflux SDK

By installing the Airflux SDK in your app, you can collect in-game data required for Airflux's model training. The installation and setup will take approximately 5 minutes.

***

## 1. Import the Airflux package

Follow the steps below to add the Airbridge SDK package file to your project.

{% tabs %}
{% tab title="Unity" %}

1. Download the latest version of the[ Airflux Unity SDK package file](https://sdk-download.airflux.ai/unity/airflux-unity-0.3.3.unitypackage).
2. Import the package file by selecting the menu option **\[Assets]>\[Import Package]>\[Custom Package]**.
3. When the import is complete, the **\[Airflux]** tab will appear in the top menu bar of the Unity Editor.
   {% endtab %}
   {% endtabs %}

## 2. Set up SDK initialization

The SDK initializes automatically every time your app is opened.&#x20;

{% hint style="info" %}
**Opt-in policy compliance** &#x20;

If player consent is required to send in-game data, implement the necessary setup by following the FAQ section below.&#x20;

[#how-can-i-set-up-the-airflux-sdk-to-comply-with-the-opt-in-policy](#how-can-i-set-up-the-airflux-sdk-to-comply-with-the-opt-in-policy "mention")
{% endhint %}

{% tabs %}
{% tab title="Unity" %}
Select **\[Airflux]>\[Airflux Settings]** from the top menu bar in the Unity Editor and configure the keys as listed below.

{% hint style="danger" %}
**Attention: Check country allowlist settings when updating SDK**

When updating the Airflux SDK from version 0.1.0 to 0.2.0, the `Country Allow All` option is set to `true` by default. As a result, after the update, all countries regardless of your existing allowlist settings are allowed to follow Airflux's optimization policies.&#x20;

If you wish to restrict countries by sticking to your existing allowlist settings, be sure to explicitly set `Country Allow All` to `false` after the update.
{% endhint %}

<table><thead><tr><th width="114.9658203125">Key</th><th>Required / Optional</th><th width="95.533203125">Data Type</th><th width="92.53125">Default</th><th>Description</th></tr></thead><tbody><tr><td>App Name</td><td>Required</td><td>string</td><td>-</td><td>Input the App Name from the Airbridge dashboard.</td></tr><tr><td>App Token</td><td>Required</td><td>string</td><td>-</td><td>Input the SDK Token from the Airbridge dashboard.</td></tr><tr><td>Log Level</td><td>Optional </td><td>string</td><td>warning</td><td>Set the log level for the Airflux SDK. Choose from <code>debug</code>, <code>info</code>, <code>warning</code>, <code>error</code>, <code>fault</code> .</td></tr><tr><td>Session Timeout Seconds</td><td>Optional</td><td>double</td><td>300</td><td>The default value is 300 seconds. Modify if needed.</td></tr><tr><td>Country Allow All</td><td>Required</td><td>boolean</td><td>true</td><td>When set to <code>true</code>, all countries are allowed to follow Airflux's optimization policies. </td></tr><tr><td>Country Allowlist</td><td>Required</td><td>array</td><td>[ ]</td><td>Set the countries where calling the Airflux's inference API should be allowed. Use country codes following the ISO 3166-1 alpha-2 format (e.g., US, KR). You can set multiple countries using the Country Allowlist array. </td></tr><tr><td>Auto Start Tracking Enabled</td><td>Optional</td><td>boolean</td><td>false</td><td>Set whether to collect events automatically upon SDK initialization.<br>- <code>true</code>:  Event collection starts automatically upon initialization.<br>- <code>false</code>: Event collection starts upon calling the  <code>Airflux.StartTracking()</code> function.</td></tr><tr><td>SDK Enabled</td><td>Optional</td><td>boolean</td><td>false</td><td>Set whether to enable the SDK upon initialization. <br>-  <code>true</code>:  The SDK is initialized in active mode.<br>- <code>false</code>: The SDK is initialized in inactive mode and is enabled upon calling the<code>Airflux.EnableSDK()</code>function.</td></tr></tbody></table>
{% endtab %}
{% endtabs %}

## Frequently Asked Questions

<details>

<summary>How can I set up the Airflux SDK to comply with the opt-in policy?</summary>

The opt-in policy requires user consent before collecting and using player data. To adhere to this policy, implement the following methods.&#x20;

1. **SDK opt-in setup**

Upon initialization of the Airflux SDK, set `Auto Start Tracking Enabled` to `false` and call the `StartTracking()` function at the point where you received user consent for data tracking. The Airflux SDK will collect data after the `StartTracking()` function is called.&#x20;

{% hint style="danger" %}
**Attention**

Although event data is not tracked before `StartTracking()` is triggered and after `StopTracking()` is triggered, player attribute data is aggregated and anonymized for transmission upon calling the Inference API.
{% endhint %}

```csharp
// After player provided consent to data tracking
Airflux.StartTracking();

//If player withdraws consent to data tracking
Airflux.StopTracking();
```

2. **Initializing the Airflux SDK in inactive mode**

{% hint style="danger" %}
**Attention**

If the SDK is not enabled immediately after the SDK initialization, the Install and Open events may not be collected.
{% endhint %}

Set `SDK Enabled` to `false` to initialize the SDK with all functions disabled until user consent for data tracking is obtained. Through this method, you can adhere to privacy policies to the highest level. Note that when the SDK is set in inactive mode, all features are disabled and no events and player attribute data is sent to Airflux.&#x20;

```csharp
// Checks whether the SDK is currently enabled.
Airbridge.IsSDKEnabled()
// Enables the SDK.
Airbridge.EnableSDK()
// Disables the SDK.
Airbridge.DisableSDK()
```

</details>

<details>

<summary>How can I configure the Airflux SDK to call the Inference API only in specific countries?</summary>

Set the "Country Allow All" to `false` and add the countries you want to allow to the "Country Allowlist". Country codes should follow the ISO 3166-1 alpha-2 format (e.g., "US", "KR"), and multiple countries can be specified by separating codes with commas.

</details>

<details>

<summary>Can I use other mediation platforms, such as MAX and AdMob, with Airflux? </summary>

Yes, Airflux is designed to work alongside existing mediation platforms.&#x20;

</details>

<details>

<summary>Is IL2CPP supported? </summary>

Yes, Airflux supports IL2CPP.

</details>

<details>

<summary>Can I use Airflux without ADID collection? </summary>

Currently, Airflux cannot be used in environments where ADID collection is not allowed.\
For further discussion or support regarding the use of Airflux in environments with ADID collection restrictions, such as children's apps, contact us at <sales@airflux.ai>.

</details>

## Troubleshooting

<details>

<summary>[Android] A coroutine dependency error occurs during the build process. </summary>

#### Issue

A coroutine dependency error occurs during the build process with the following message.

```
java.lang.NoClassDefFoundError: kotlin/coroutines/AbstractCoroutineContextKey
    at java.base/java.lang.ClassLoader.defineClass1(Native Method)
    at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016)
  ...
```

#### Cause

If the kotlinx-coroutines-core library version is 1.3.5 or later, [the kotlin-stdlib library version must be at a certain level or later](https://github.com/Kotlin/kotlinx.coroutines/issues/1879).

#### Solution

Check whether the kotlin-stdlib library version is v.1.3.70 or later with the `gradlew dependencies` command. If the version is earlier than v.1.3.70, you need to update it.

</details>

<details>

<summary>[Android] The "Manifest merger failed" error occurs during the build process.</summary>

#### Issue&#x20;

The "Manifest merger failed" error occurs during the build process.

#### Cause

The Airbridge SDK's `AndroidManifest.xml` includes rules to opt out of backing up the Shared Preferences data. The purpose of this rule is to avoid retaining the same Airbridge settings during the reinstallation of the app so that new installs or reinstalls can be detected accurately.

Merging Airbridge SDK backup rules with your app backup rules can cause conflicts.

#### Solution

Below are the opt-out rules defined in the Airbridge SDK.

Backup on Android 12 or laterBackup on Android 11 and earlier.

```
<?xml version="1.0" encoding="utf-8"?>
<data-extraction-rules>
    <cloud-backup>
        <exclude domain="sharedpref" path="airbridge-internal" />
        <exclude domain="sharedpref" path="airbridge-install" />
        <exclude domain="sharedpref" path="airbridge-user-info" />
        <exclude domain="sharedpref" path="airbridge-user-alias" />
        <exclude domain="sharedpref" path="airbridge-user-attributes" />
        <exclude domain="sharedpref" path="airbridge-device-alias" />
        <exclude domain="database" path="airbridge.db" />
    </cloud-backup>
    <device-transfer>
        <exclude domain="sharedpref" path="airbridge-internal" />
        <exclude domain="sharedpref" path="airbridge-install" />
        <exclude domain="sharedpref" path="airbridge-user-info" />
        <exclude domain="sharedpref" path="airbridge-user-alias" />
        <exclude domain="sharedpref" path="airbridge-user-attributes" />
        <exclude domain="sharedpref" path="airbridge-device-alias" />
        <exclude domain="database" path="airbridge.db" />
    </device-transfer>
</data-extraction-rules>
```

**Fix conflict with fullBackupContent="string"**

Adding `android:fullBackupContent="string"` to the `AndroidManifest.xml` file may cause an error like the following.

Build Output

```
Manifest merger failed : Attribute application@fullBackupContent value=(string) from AndroidManifest.xml
```

To fix this error,

* add `xmlns:tools="http://schemas.android.com/tools"` to the `<manifest>` tag
* add `tools:replace="android:fullBackupContent"` to the `<application>` tag

in the Custom Main Manifest(`Assets/Plugins/Android/AndroidManifest.xml`) file.

**Fix conflict with dataExtractionRules="string resource"**

Adding `android:dataExtractionRules="string resource"` to the `AndroidManifest.xml` file may cause an error like the following.

Build Output

```
Manifest merger failed : Attribute application@dataExtractionRules value=(string resource) from AndroidManifest.xml
```

To fix this error,

* add `xmlns:tools="http://schemas.android.com/tools"` to the `<manifest>` tag
* add `tools:replace="android:dataExtractionRules"` to the `<application>` tag

in the Custom Main Manifest(`Assets/Plugins/Android/AndroidManifest.xml`) file.

**Fix conflict with allowBackup="false"**

Adding `android:allowBackup="false"` to the `AndroidManifest.xml` file may cause an error like the following.

Build Output

```
Manifest merger failed : Attribute application@allowBackup value=(false) from AndroidManifest.xml:32:9-36
	is also present at [:airbridge] AndroidManifest.xml:27:9-35 value=(true).
	Suggestion: add 'tools:replace="android:allowBackup"' to <application> element at AndroidManifest.xml:30:5-250:19 to override.
```

To fix this error,

* add `xmlns:tools="http://schemas.android.com/tools"` to the `<manifest>` tag
* add `tools:replace="android:allowBackup"` to the `<application>` tag

in the Custom Main Manifest(`Assets/Plugins/Android/AndroidManifest.xml`) file.

**If compileSdkVersion is lower than 31**

The `android:dataExtractionRules` has been added in API Level 31. Therefore, if the compileSdkVersion is lower than 31, an error like the following may occur.

Build Output

```
AndroidManifest.xml: AAPT: error: attribute android:dataExtractionRules not found.
```

To fix this error,

* add `xmlns:tools="http://schemas.android.com/tools"` to the `<manifest>` tag
* add `tools:remove="android:dataExtractionRules"` to the `<application>` tag

in the Custom Main Manifest(`Assets/Plugins/Android/AndroidManifest.xml`) file.

For more guidance, refer to the articles below.

* [Android Developers Guide](https://developer.android.com/identity/data/autobackup)<br>

</details>

<details>

<summary>[Android] Conflict occurs when merging the Airflux SDK backup rules.</summary>

#### Issue

If an Airflux SDK backup rule and a backup rule for a different third-party SDK (e.g., AppsFlyer SDK) overlap, you will see the build error below.

```
Attribute application@fullBackupContent value=(@xml/appsflyer_backup_rules) from [com.appsflyer:af-android-sdk:6.6.1] AndroidManifest.xml:14:18-73
is also present at [io.airbridge:sdk-android:2.14.0] AndroidManifest.xml:27:18-78 value=(@xml/airbridge_auto_backup_rules).
Suggestion: add 'tools:replace="android:fullBackupContent"' to <application> element at AndroidManifest.xml:7:5-13:19 to override.
```

#### Cause

Overlapping of the Airflux SDK backup rules and third-party SDK backup rules can cause build errors.

#### Solution

**`backup_rules.xml` setup**

1. Create an Android Library project (`Assets/Plugins/Android/res.androidlib`) to store your resource files.
2. Add an `AndroidManifest.xml` file in the created Android Library Project as follows.

   123456

   ```
   <?xml version="1.0" encoding="utf-8"?>
   <manifest xmlns:android="http://schemas.android.com/apk/res/android"
             package="custom.android.res"
             android:versionCode="1"
             android:versionName="1.0">
   </manifest>
   ```
3. Create a `res/xml` folder inside the created Android Library Project.
4. Create a file (e.g., `custom_backup_rules.xml`) within the new xml folder.
5. Add the data backup rules defined by the Airflux SDK as follows.

   12345678910111213141516

   ```
   <?xml version="1.0" encoding="utf-8"?>
   <full-backup-content>
       <!-- Airbridge Backup Rules -->
       <exclude domain="sharedpref" path="airbridge-internal" />
       <exclude domain="sharedpref" path="airbridge-install" />
       <exclude domain="sharedpref" path="airbridge-user-info" />
       <exclude domain="sharedpref" path="airbridge-user-alias" />
       <exclude domain="sharedpref" path="airbridge-user-attributes" />
       <exclude domain="sharedpref" path="airbridge-device-alias" />
       <exclude domain="database" path="airbridge.db" />
     
       <!-- Appsflyer Backup Rules -->
       <exclude domain="sharedpref" path="appsflyer-data"/>
   	
   	<!-- Your Custom Backup Rules -->
   </full-backup-content>
   ```

**`data_extraction_rules.xml` setup**

1. Create a file (e.g., `custom_data_extraction_rules.xml`) within the new xml folder.
2. Add the data backup rules defined by the Airflux SDK as follows.

   ```
   <?xml version="1.0" encoding="utf-8"?>
   ```

   ```
   <data-extraction-rules>
       <cloud-backup>
           <!-- Airbridge Backup Rules -->
           <exclude domain="sharedpref" path="airbridge-internal" />
           <exclude domain="sharedpref" path="airbridge-install" />
           <exclude domain="sharedpref" path="airbridge-user-info" />
           <exclude domain="sharedpref" path="airbridge-user-alias" />
           <exclude domain="sharedpref" path="airbridge-user-attributes" />
           <exclude domain="sharedpref" path="airbridge-device-alias" />
           <exclude domain="database" path="airbridge.db" />

           <!-- Appsflyer Backup Rules -->
           <exclude domain="sharedpref" path="appsflyer-data"/>

   	    <!-- Your Custom Backup Rules -->
       </cloud-backup>
       <device-transfer>
           <!-- Airbridge Backup Rules -->
           <exclude domain="sharedpref" path="airbridge-internal" />
           <exclude domain="sharedpref" path="airbridge-install" />
           <exclude domain="sharedpref" path="airbridge-user-info" />
           <exclude domain="sharedpref" path="airbridge-user-alias" />
           <exclude domain="sharedpref" path="airbridge-user-attributes" />
           <exclude domain="sharedpref" path="airbridge-device-alias" />
           <exclude domain="database" path="airbridge.db" />

           <!-- Appsflyer Backup Rules -->
           <exclude domain="sharedpref" path="appsflyer-data"/>

   	    <!-- Your Custom Backup Rules -->
       </device-transfer>
   </data-extraction-rules>
   ```

**`AndroidManifest.xml` setup**

Apply the data backup rules to the Android App Manifest file (`Assets/Plugins/Android/AndroidManifest.xml`) as follows.

```
<manifest
    ...
    xmlns:tools="http://schemas.android.com/tools">

    <application
        ...
		android:allowBackup="true"
		android:fullBackupContent="@xml/custom_backup_rules"
        android:dataExtractionRules="@xml/custom_data_extraction_rules"
		tools:replace="android:fullBackupContent, android:dataExtractionRules">
```

For more guidance, refer to the articles below.

* [Import an Android Library Project](https://docs.unity3d.com/2022.3/Documentation/Manual/android-library-project-import.html)
* [Override the Android App Manifest](https://docs.unity3d.com/2022.3/Documentation/Manual/overriding-android-manifest.html)

</details>
