> ## Documentation Index
> Fetch the complete documentation index at: https://developer.onetrust.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Download and Import the SDK

> Supports Android Mobile, Android TV, and Fire TV applications.

The Android SDK can be imported 2 ways:

1. Maven package manager
2. `.aar` framework

## Maven Package Manager

The OneTrust SDK is published and distributed through [Maven repository](https://mvnrepository.com/artifact/com.onetrust.cmp/native-sdk). Add it to your app as a build dependency.

1. In your project's build gradle, add the following to `buildscript`:

```groovy
repositories {
	mavenCentral()
} 
```

2. In your app's build gradle, add the following under `dependencies`:

```groovy
// Implement the SDK version that corresponds to the published API version
implementation 'com.onetrust.cmp:native-sdk:X.X.0.0'

// Example: 
implementation 'com.onetrust.cmp:native-sdk:202507.1.0.0'
```

3. Sync and build.

### Dependencies and Dependency Conflicts

**Dependencies**

The OneTrust SDK uses the following dependencies.  Make sure to include or exclude based on your current project.  Not having these will cause runtime exceptions.

```groovy
// mandatory
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.google.android.material:material:1.11.0'
implementation 'androidx.work:work-runtime:2.9.0'
implementation 'androidx.browser:browser:1.7.0'
implementation 'com.github.bumptech.glide:glide:4.10.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.7.0'
implementation 'androidx.fragment:fragment-ktx:1.6.2'
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.7.10"
implementation 'com.squareup.retrofit2:converter-scalars:2.8.1'

// optional: Only when the SDK needs to measure Google Ad Id Opt In/Outs
implementation 'com.google.android.gms:play-services-ads-identifier:18.0.1'
// optional for QR code display on TV UI
implementation 'com.google.zxing:core:3.3.0'
  
// for cmp api implementations 
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4"   
```

Add the following code snippet to the `android()` section of the app's gradle file

```groovy
buildFeatures {
  viewBinding true
}
```

**Optional Dependencies**

*Google Ad ID*

The Android SDK has the capability to measure the opt-in/out rates of Google's Advertising Id.  [According to Google](https://support.google.com/googleplay/android-developer/answer/6048248?hl=en), starting in late 2021 when a user opts out of interest-based advertising or ads personalization, the advertising identifier will not be available and will be a string of 0's.

If you'd like to measure the opt in/out rate, include the following dependency:

```groovy
implementation 'com.google.android.gms:play-services-ads:7.8.0'
```

*QR Code for Android TV*

In order to show a privacy policy link as a QR code on Android TV, add the following dependency:

```groovy
implementation 'com.google.zxing:core:3.3.0' 
```

**Dependency Conflicts**

The SDK includes several dependencies that you may already have in your project. If you experience a dependency conflict, try excluding the OneTrust SDK's runtime dependencies and re-build. Example reference below.

```groovy
// Make sure the com.onetrust.cmp:native-sdk:[version] matches what you're implementing.

implementation ('com.onetrust.cmp:native-sdk:202507.1.0.0') {
	exclude group: 'com.google.android.gms'
}
```

### Known Issues

**Gradle Version 8+**

There is a known issue with Gradle version 8+ where the application is facing a build error with R8.

**Solution 1:** Add the optional dependencies below in the app's build.gradle file

```groovy
 implementation ("com.google.android.gms:play-services-ads-identifier:18.0.1")
 implementation ("com.google.zxing:core:3.3.0")
```

**Solution 2:** In app's `proguard-rules.pro` file, add the following rules:

```text ProGuard
# Ignoring implementation ("com.google.zxing:core:3.3.0") dependencies
	-dontwarn com.google.zxing.**

# Ignoring implementation ("com.google.android.gms:play-services-ads-identifier:18.0.1") dependencies
	-dontwarn com.google.android.gms.ads.identifier.AdvertisingIdClient$Info
	-dontwarn com.google.android.gms.ads.identifier.AdvertisingIdClient
```

**Gradle Version 8+ if `isMinifyEnabled = true`**

With Gradle version 8+, if the app sets `isMinifyEnabled = true`, it may crash on runtime when `startSDK()` is called.

The OneTrust SDK uses `Retrofit` for network calls which requires some proguard rule updates if the app is using R8 shrinking and obfuscation rules. More info in the links below:

<https://github.com/square/retrofit?tab=readme-ov-file#r8--proguard>\
<https://github.com/square/retrofit/blob/trunk/retrofit/src/main/resources/META-INF/proguard/retrofit2.pro>

To resolve the crash, add the following to the `proguard-rules.pro`:

**Option 1:**\
R8 full mode strips generic signatures from return types if not kept.

```Text ProGuard
 -if interface * { @retrofit2.http.* public *** *(...); }
	 -keep,allowoptimization,allowshrinking,allowobfuscation class <3>
```

**Option 2:**\
Add the following rule:

```Text ProGuard
-keep class retrofit2.** { *; }
```

**D8 Exceptions**

On compile, if you experience any D8 exceptions with the aforementioned Gradle versions, add the following to your app’s Gradle file:

```groovy
compileOptions {    
	sourceCompatibility = '1.8'    
	targetCompatibility = '1.8'
}
```

<br />

## Import `.aar` Framework

**Download the SDK**

1. In the OneTrust tenant, navigate to Mobile App Consent > SDKs.
2. Select your Android application from the list.
3. Select the SDK tab > Your App Framework (e.g. Native SDK) > Select an SDK version to download > Download SDK

![](https://files.readme.io/b78883ecc13728d9fc3318ff11f64fbf0acccaf15a94ea2c80b84cb655016b12-image.png)

**What's in the Download Package?**

| File Name                           | Description                                     |
| ----------------------------------- | ----------------------------------------------- |
| OTPublishersNativeApp               | Sample app to demo the functionality of the SDK |
| CHANGELOG                           | Changelog to document version changes           |
| LICENSE                             | SDK usage license policy                        |
| OTPublishersHeadlessSDK-release.aar | OneTrust SDK .aar file                          |
| README                              | Readme containing implementation instructions   |

**Import the SDK to your Project**

1. Place the `OTPublishersHeadlessSDK-release.aar` file inside your project's **libs** folder
2. Navigate to File > Project Structure > Dependencies
3. In the Declared Dependencies tab, click **+** and select **Jar/AAR Dependency** in the dropdown
4. In the **Add Jar/AAR Dependency** dialog box, enter the path to the OneTrust .aar file, then select **implementation**

[block:image]
{
  "images": [
    {
      "image": [
        "https://files.readme.io/6e3e2ba-Screenshot_2022-11-18_at_12.01.08.png",
        null,
        ""
      ],
      "align": "center",
      "sizing": "600px"
    }
  ]
}
[/block]

5. Check your app's build.gradle file to confirm the declaration.

```groovy
implementation files('libs/OTPublishersHeadlessSDK-release.arr')
```

6. Include the dependencies [(listed above)](https://developer.onetrust.com/onetrust/docs/adding-sdk-to-app-android-next-gen#dependencies-and-dependency-conflicts) if it's not already included in your app.

## Import Statement

```java
import com.onetrust.otpublishers.headless.Public.OTCallback;
import com.onetrust.otpublishers.headless.Public.OTPublishersHeadlessSDK;
```