# 2. Install the Airflux SDK

## 1. SDK Installation

{% stepper %}
{% step %}

#### Declare the SDK Repository

To install the Airflux Android SDK, you need to declare the SDK repository to only one file `settings.gradle` or `build.gradle`.

**Case A**: If your project-level `settings.gradle` file contains `dependencyResolutionManagement` block, add the SDK repository to the `repositories` block in the file.

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

```groovy
dependencyResolutionManagement {
    repositories {
        maven { url = "https://sdk-download.airflux.ai/maven" }
    }
}
```

{% endtab %}

{% tab title="Kotlin DSL" %}

```kotlin
dependencyResolutionManagement {
    repositories {
        maven { url = uri("https://sdk-download.airflux.ai/maven") }
    }
}
```

{% endtab %}
{% endtabs %}

**Case B**: If your project-level `build.gradle` file contains `allprojects` block, add the SDK repository to the `repositories` block in the file.

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

```groovy
allprojects {
    repositories {
        maven { url = "https://sdk-download.airflux.ai/maven" }
    }
}
```

{% endtab %}

{% tab title="Kotlin DSL" %}

```kotlin
allprojects {
    repositories {
        maven { url = uri("https://sdk-download.airflux.ai/maven") }
    }
}
```

{% endtab %}
{% endtabs %}
{% endstep %}

{% step %}

#### Add the SDK Package

Add the SDK as a dependency in your app-level `app/build.gradle` file. Replace `$HERE_LATEST_VERSION` with the latest SDK version, available on the [<mark style="color:blue;">Airflux SDK Versions page</mark>](https://sdk-download.airflux.ai/maven/ai/airflux/sdk-android/index.html).

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

```groovy
dependencies {
    // Replace $HERE_LATEST_VERSION with the latest version from the SDK Versions page.
    implementation "ai.airflux:sdk-android:$HERE_LATEST_VERSION"
}
```

{% endtab %}

{% tab title="Kotlin DSL" %}

```kotlin
dependencies {
    // Replace $HERE_LATEST_VERSION with the latest version from the SDK Versions page.
    implementation("ai.airflux:sdk-android:$HERE_LATEST_VERSION")
}
```

{% endtab %}
{% endtabs %}
{% endstep %}
{% endstepper %}

***

## 2. SDK Initialization

{% stepper %}
{% step %}

#### Create a Custom MainApplication

To enable this, create a custom `MainApplication` class and register it in your `AndroidManifest.xml` file.

{% code title="AndroidManifest.xml" %}

```xml
<application
    android:name=".MainApplication"
    ...>
```

{% endcode %}
{% endstep %}

{% step %}

#### Initialize the SDK

Initialize the SDK within the `onCreate()` method of your `MainApplication` class. This ensures the SDK is ready as soon as the app launches.

{% hint style="info" %}
Your **YOUR\_APP\_NAME** and **YOUR\_APP\_SDK\_TOKEN** credentials are available in the Airbridge dashboard via \[Settings] > \[Token Management].
{% endhint %}

<table><thead><tr><th width="125.76171875">SDK Option</th><th width="215.71484375">Method</th><th width="118.22265625">Data Type</th><th width="295.0703125">Description</th><th>Required</th></tr></thead><tbody><tr><td>App Name</td><td><code>AirfluxOptionBuilder()</code></td><td><code>string</code></td><td>Input the App Name from the Airbridge dashboard.</td><td><strong>Required</strong></td></tr><tr><td>App Token</td><td><code>AirfluxOptionBuilder()</code></td><td><code>string</code></td><td>Input the App Token from the Airbridge dashboard.</td><td><strong>Required</strong></td></tr><tr><td>SDK Enabled</td><td><code>setSDKEnabled()</code></td><td><code>boolean</code></td><td><p>Set whether to enable the SDK upon initialization.</p><ul><li>true: The SDK is initialized in active mode.</li><li>false: The SDK is initialized in inactive mode and is enabled upon calling the <code>Airflux.EnableSDK()</code> function.</li></ul></td><td>Optional</td></tr><tr><td>Auto Start Tracking Enabled</td><td><code>setAutoStartTrackingEnabled()</code></td><td><code>boolean</code></td><td><p>Set whether to collect events automatically upon SDK initialization.</p><ul><li>true: Event collection starts automatically upon initialization.</li><li>false: Event collection starts upon calling the <code>Airflux.StartTracking()</code> function.</li></ul></td><td>Optional</td></tr><tr><td>Log Level</td><td><code>setLogLevel()</code></td><td><code>AirfluxLogLevel</code></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><td>Optional</td></tr><tr><td>Session Timeout</td><td><code>setSessionTimeout()</code></td><td><code>double</code></td><td>The default value is 300 seconds. Modify if needed.</td><td>Optional</td></tr><tr><td>Allow Every Country Enabled</td><td><code>setAllowEveryCountryEnabled()</code></td><td><code>boolean</code></td><td>When set to true, all countries are allowed to follow Airflux's optimization policies. To use a specific list of countries, set it to false and provide a list using <code>setCountryAllowlist()</code>.</td><td>Optional</td></tr><tr><td>Country Allowlist</td><td><code>setCountryAllowlist()</code></td><td><code>List&#x3C;String></code></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. Airflux identifies a country based on the value tied to the device.</td><td>Optional</td></tr></tbody></table>

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

```kotlin
import ai.airflux.Airflux
import ai.airflux.AirfluxOptionBuilder
import ai.airflux.AirfluxLogLevel
import android.app.Application

class MainApplication : Application() {

    override fun onCreate() {
        super.onCreate()

        // Creates the option for initializing the Airflux SDK.
        // Replace "YOUR_APP_NAME" and "YOUR_APP_TOKEN" with your actual credentials.
        val option = AirfluxOptionBuilder("YOUR_APP_NAME", "YOUR_APP_TOKEN")
            // Automatically enables the SDK on startup.
            .setSDKEnabled(true)
            // Automatically starts tracking events.
            .setAutoStartTrackingEnabled(true)
            // Sets the log level to debug for detailed logs.
            .setLogLevel(AirfluxLogLevel.DEBUG)
            // Sets the session timeout to 300 seconds (5 minutes).
            .setSessionTimeout(300)
            // Allows Airflux features in all countries.
            .setAllowEveryCountryEnabled(true)
            // Uncomment the line below to allow only specific countries.
            // .setCountryAllowlist(listOf("US", "KR", "JP"))
            .build()

        Airflux.initializeSDK(this, option)
    }
}
```

{% endtab %}

{% tab title="Java" %}

```java
import ai.airflux.Airflux;
import ai.airflux.AirfluxOption;
import ai.airflux.AirfluxOptionBuilder;
import ai.airflux.AirfluxLogLevel;
import android.app.Application;
import java.util.Arrays;
import java.util.List;

public class MainApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        
        final AirfluxOption option = new AirfluxOptionBuilder("YOUR_APP_NAME", "YOUR_APP_TOKEN")
            // Automatically enables the SDK on startup.
            .setSDKEnabled(true)
            // Automatically starts tracking events.
            .setAutoStartTrackingEnabled(true)
            // Sets the log level to debug for detailed logs.
            .setLogLevel(AirfluxLogLevel.DEBUG)
            // Sets the session timeout to 300 seconds (5 minutes).
            .setSessionTimeout(300)
            .setAllowEveryCountryEnabled(true)
            // Uncomment the line below to allow only specific countries.
            // .setCountryAllowlist(Arrays.asList("US", "KR", "JP"))
            .build();

        // Initializes the SDK using the configured option.
        Airflux.initializeSDK(this, option);
    }
}
```

{% endtab %}
{% endtabs %}
{% endstep %}
{% endstepper %}

***

## 3. Verification

#### **Android Logcat check**

To view detailed log information for your app, use the Android Logcat tool.

{% hint style="warning" %}
You can set the log output level using the `setLogLevel` function. \
Setting it to `AirfluxLogLevel.DEBUG` allows you to see all Airflux logs.
{% endhint %}

***

## 4. Frequently Asked Questions

{% hint style="info" %}
Opt-in policy compliance

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?](https://docs.airflux.ai/airflux-onboarding/airflux-integration/2.-install-the-airflux-sdk#how-can-i-set-up-the-airflux-sdk-to-comply-with-the-opt-in-policy)
{% endhint %}

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

1. **SDK opt-in setup**

Upon initialization of the Airflux SDK, set the initialization option `setAutoStartTrackingEnabled()`to `false` and call the `startTracking()` function at the point where you have received user consent for data tracking. The Airflux SDK will collect data after the `startTracking()` function is called.

{% hint style="warning" %}
**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="warning" %}
**Attention**

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

Set the initialization option `setSDKEnabled()` 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.

</details>

<details>

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

Set the initialization opeion `setAllowEveryCountryEnabled()` 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. Country codes are not case-sensitive.

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

</details>

<details>

<summary>How does Airflux determine a user’s country?</summary>

Airflux distinguishes a country based on the value tied to the deivce.

</details>

<details>

<summary>Does Airflux collect the ADID (Advertising ID)?</summary>

No. The Airflux SDK operates without collecting or requiring the ADID.

</details>

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

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


---

# 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.airflux.ai/airflux-onboarding/airflux-integration-android/2.-install-the-airflux-sdk.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.
