Download and Import the SDK
Supports Android Mobile, Android TV, and Fire TV applications.
The Android SDK can be imported 2 ways:
- Maven package manager
.aar
framework
Maven Package Manager
The OneTrust SDK is published and distributed through Maven repository. Add it to your app as a build dependency.
- In your project's build gradle, add the following to
buildscript
:
repositories {
mavenCentral()
}
- In your app's build gradle, add the following under
dependencies
:
// 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'
- 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.
// 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
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, 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:
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:
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.
// 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
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:
# Ignoring implementation ("com.google.zxing:core:3.3.0") dependencies.
-dontwarn com.google.zxing.BarcodeFormat
-dontwarn com.google.zxing.EncodeHintType
-dontwarn com.google.zxing.MultiFormatWriter
-dontwarn com.google.zxing.common.BitMatrix
# 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.
-if interface * { @retrofit2.http.* public *** *(...); }
-keep,allowoptimization,allowshrinking,allowobfuscation class <3>
Option 2:
Add the following rule similar to https://developer-onetrust-com.proxy-tu.researchport.umd.edu/onetrust/docs/android#frequently-asked-questions-faq
-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:
compileOptions {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}
Import .aar
Framework
.aar
FrameworkDownload the SDK
- In the OneTrust tenant, navigate to Mobile App Consent > SDKs.
- Select your Android application from the list.
- Select the SDK tab > Your App Framework (e.g. Native SDK) > Select an SDK version to download > Download SDK
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
- Place the
OTPublishersHeadlessSDK-release.aar
file inside your project's libs folder - Navigate to File > Project Structure > Dependencies
- In the Declared Dependencies tab, click + and select Jar/AAR Dependency in the dropdown
- In the Add Jar/AAR Dependency dialog box, enter the path to the OneTrust .aar file, then select implementation

- Check your app's build.gradle file to confirm the declaration.
implementation files('libs/OTPublishersHeadlessSDK-release.arr')
- Include the dependencies (listed above) if it's not already included in your app.
Import Statement
import com.onetrust.otpublishers.headless.Public.OTCallback;
import com.onetrust.otpublishers.headless.Public.OTPublishersHeadlessSDK;
Updated 2 days ago