# Android

The SDK is available as an AAR (recommended) and JAR library. The library is available in the MavenCentral and [GitHub repository](https://github.com/devtodev-analytics/android-sdk-2.0).

### Step 1. Gradle Build Dependencies

If you use Gradle for building apps specify the following dependencies in the **`build.gradle`** file in the dependencies block.

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

```kotlin
dependencies {
    implementation ‘androidx.preference:preference-ktx:1.1.1
    implementation 'com.android.installreferrer:installreferrer:2.2'
    implementation 'com.google.android.gms:play-services-base:17.6.0'
    implementation 'com.google.code.gson:gson:2.8.6'
    implementation 'com.google.firebase:firebase-core:19.0.0'
    // if you use AAR (recommended) or JAR downloaded from GitHub, please add:
    implementation fileTree(dir: "libs", include: ["*.aar"]) 
    // or just add the dependency
    implementation 'com.devtodev:android-analytics:2.0.0'
}
```

{% endtab %}

{% tab title="Java" %}

```java
dependencies {
    implementation ’androidx.preference:preference:1.1.1
    implementation 'com.android.installreferrer:installreferrer:2.2'
    implementation 'com.google.android.gms:play-services-base:17.6.0'
    implementation 'com.google.code.gson:gson:2.8.6'
    implementation 'com.google.firebase:firebase-core:19.0.0'
    // if you use AAR (recommended) or JAR downloaded from GitHub, please add:
    implementation fileTree(dir: "libs", include: ["*.aar"]) 
    // or just add the dependency
    implementation 'com.devtodev:android:2.0.0'
}
```

{% endtab %}
{% endtabs %}

### Step 2. SDK Initialization

Use the following way to initialize the library in the first Activity **`onCreate()`** method:

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

```kotlin
class MainActivity : Activity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
      
        val analyticsConfiguration = DTDAnalyticsConfiguration()
        analyticsConfiguration.logLevel = DTDLogLevel.Error
        DTDAnalytics.initialize("App ID", analyticsConfiguration, context)
    }
}
```

{% endtab %}

{% tab title="Java" %}

```java
public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        DTDAnalyticsConfiguration configuration = new DTDAnalyticsConfiguration();
        configuration.setLogLevel(DTDLogLevel.Error);
        DTDAnalytics.initialize("App ID", configuration, context);
    }
}
```

{% endtab %}
{% endtabs %}

* You can find the **App ID** in the settings of the respective app in devtodev (Settings → SDK → Integration → Credentials).
* **`config`** - is a **`DTDAnalyticsConfiguration`** object instance that is used for specifying additional properties during initialization.

**`DTDAnalyticsConfiguration`**

| Parameter                  | Type                     | Description                                                                                                                                                                                                                                                                                                                      |
| -------------------------- | ------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **`currentLevel`**         | Integer                  | The player level at the moment of devtodev SDK initialization. It’s optional but we recommend using it for improving data accuracy.                                                                                                                                                                                              |
| **`userId`**               | String                   | A custom user ID assigned by the developer. In the case of default calculation by device IDs, the identifier can be used for searching users in devtodev. In case the project uses calculation by user IDs, the parameter is mandatory because it becomes the principal calculation ID in devtodev.                              |
| **`trackingAvailability`** | DTDTrackingStatus (enum) | The property allows or disallows devtodev tracking of the user. By default, it is set to ***`DTDTrackingStatus.enable`***. SDK stores the previously assigned value. Pass ***`DTDTrackingStatus.disable`*** if the user opted out of tracking in line with GDPR.                                                                 |
| **`logLevel`**             | DTDLogLevel (enum)       | The level of logging the SDK activity. The ***`DTDLogLevel.no`*** value is used by default. For troubleshooting during integration it is recommended to set it to ***`DTDLogLevel.debug`***, and either switch it off ***`DTDLogLevel.no`*** or use it only for error handling ***`DTDLogLevel.error`*** in the release version. |

Example:

```kotlin
let config = DTDAnalyticsConfiguration()
config.currentLevel = 1
config.userId = "CustomUserID"
config.trackingAvailability = DTDTrackingStatus.Enable
config.logLevel = .error
DTDAnalytics.initialize(applicationKey: "appKey", configuration: config)
```

### **Step 3. SDK Initialization**

Add the following strings to the **`proguard-rules.pro`** file of your app

```kotlin
-keep class com.devtodev.** { *; }
-dontwarn com.devtodev.**
```


---

# 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.devtodev.com/in-developing/integration-of-sdk/sdk-integration/android.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.
