Getting started with the Android SDK
This guide walks you through the initial setup of the Adtrace Android SDK. You'll learn how to install the SDK, configure your project, initialize the SDK, and verify that your integration is successful. By the end of this guide, your app will be ready to track installs, sessions, and events.
Choose your integration type
This page covers native Android apps (Java / Kotlin). For TWA or WebBridge, choose your path on the Android SDK overview.
1. Get the Adtrace SDK
Add the Adtrace SDK to your Android project using one of these methods:
- Maven (recommended): add the dependency below to your app
build.gradlefile. Latest versions are also listed on the Maven Central Repository. - JAR / AAR: download the SDK from the GitHub releases page.
These steps assume you are using Android Studio. If your app uses an Android WebView, also complete the WebBridge (WebView) guide after the native setup steps (or use Case A if tracking is JS-only). For Google Play Store apps, also complete Add Install Referrer.
The minimum supported Android API level for the Adtrace SDK integration is 21 (Android 5.0 / Lollipop).
Maven
If you are using Maven, add the following to your build.gradle file:
dependencies {
implementation 'io.adtrace:android-sdk:3.0.1'
}
2. Add Google Play Services
Apps that target the Google Play Store must use the Google Advertising ID (gps_adid) to identify devices. Add the play-services-ads-identifier dependency so the Adtrace SDK can read it:
dependencies {
implementation 'com.google.android.gms:play-services-ads-identifier:18.0.1'
}
3. Add Install Referrer
Apps that target the Google Play Store must use the Google Play Referrer API so Adtrace can attribute installs. Add the Install Referrer library to your app:
dependencies {
implementation 'com.android.installreferrer:installreferrer:2.2'
}
If you use Proguard or R8, keep the Install Referrer classes. The required rule is already included in Set up Proguard.
If you distribute on Myket, also add the optional Myket install referrer plugin. If you distribute on Cafe Bazaar, add the optional Cafe Bazaar install referrer plugin. Apps that target Google Play alone can skip both.
4. Add Permissions
Declare the permissions the Adtrace SDK needs in your AndroidManifest.xml.
Required permissions
Add these permissions for network access:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
If your app does not target the Google Play Store
Add this permission so the SDK can read network state:
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
Google Advertising ID (AD_ID)
If your app targets Android 12 (API level 31) or higher and the Google Play Store, add this permission so the SDK can read the advertising ID (gps_adid):
<uses-permission android:name="com.google.android.gms.permission.AD_ID"/>
If your app targets children (COPPA / Play Store Kids) or must not read the advertising ID, remove the permission instead:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="com.google.android.gms.permission.AD_ID" tools:node="remove"/>
</manifest>
See apps for children for the full kids setup.
5. Set up Proguard
If you use Proguard (or R8) to optimize your app, add these rules so required classes are not removed.
-keep class io.adtrace.sdk.** { *; }
-keep class com.google.android.gms.common.ConnectionResult {
int SUCCESS;
}
-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient {
com.google.android.gms.ads.identifier.AdvertisingIdClient$Info getAdvertisingIdInfo(android.content.Context);
}
-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient$Info {
java.lang.String getId();
boolean isLimitAdTrackingEnabled();
}
-keep public class com.android.installreferrer.** { *; }
If your app does not target the Google Play Store
Add this rule as well:
-keep public class io.adtrace.sdk.** { *; }
6. Initialize the Adtrace SDK
This section is for native Android apps (Java / Kotlin). For WebView apps, go to WebBridge (WebView). For Trusted Web Activity, follow the TWA documentation.
To initialize the Adtrace SDK you need:
appToken: your Adtrace app token from the Adtrace panelenvironment: useAdTraceConfig.ENVIRONMENT_SANDBOXwhile testing andAdTraceConfig.ENVIRONMENT_PRODUCTIONbefore you publish. Adtrace uses this to separate test traffic from real traffic. Switch back to sandbox when you test again.
Initialize the SDK in a global Android Application class. If you do not have one yet, follow these steps:
- Create a class that extends
Application. - Open
AndroidManifest.xmland find the<application>element. - Set
android:nameto your application class. For example, if the class isGlobalApplication:
<application
android:name=".GlobalApplication">
<!-- ... -->
</application>
- In your
Applicationclass, initialize Adtrace inonCreate:
- Java
- Kotlin
import android.app.Application;
import io.adtrace.sdk.AdTrace;
import io.adtrace.sdk.AdTraceConfig;
public class GlobalApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
String appToken = "{YourAppToken}";
String environment = AdTraceConfig.ENVIRONMENT_SANDBOX;
AdTraceConfig config = new AdTraceConfig(this, appToken, environment);
AdTrace.onCreate(config);
}
}
import android.app.Application
import io.adtrace.sdk.AdTrace
import io.adtrace.sdk.AdTraceConfig
class GlobalApplication : Application() {
override fun onCreate() {
super.onCreate()
val appToken = "{YourAppToken}"
val environment = AdTraceConfig.ENVIRONMENT_SANDBOX
val config = AdTraceConfig(this, appToken, environment)
AdTrace.onCreate(config)
}
}
Replace {YourAppToken} with your app token from the Adtrace panel.
- Set
environmentbased on your stage:
- Java
- Kotlin
// Testing
String environment = AdTraceConfig.ENVIRONMENT_SANDBOX;
// Production (before release)
String environment = AdTraceConfig.ENVIRONMENT_PRODUCTION;
// Testing
val environment = AdTraceConfig.ENVIRONMENT_SANDBOX
// Production (before release)
val environment = AdTraceConfig.ENVIRONMENT_PRODUCTION
From Adtrace Android SDK 3.0.0+, lifecycle and session tracking are handled automatically after AdTrace.onCreate(config). You do not need to call AdTrace.onResume() / AdTrace.onPause() or register ActivityLifecycleCallbacks for Adtrace.
If you integrate SDK 2.6.0, switch the docs version to 2.6.0 for the manual session-tracking steps.
7. WebBridge
Optional. Only for apps that use an Android WebView. Native-only apps can skip to 8. Test the integration. For TWA apps, use the TWA documentation instead. Do not use WebBridge for TWA.
If your app loads content in a WebView and you need Adtrace to record activity from that web layer, follow the dedicated WebBridge (WebView) guide.
That guide covers:
- Case A (WebBridge-only): initialize from JavaScript
- Case B (hybrid): initialize from native, track from native and JS
- Bridge registration, JS assets, APIs, and troubleshooting
Initialize Adtrace once per process (native or JS). Calling onCreate twice logs AdTrace already initialized.
See also the WebBridge example app.
8. Test the integration
A successful install (first open after install) must be recorded before sessions and events appear correctly in Adtrace. Use the steps below to verify your integration.
Prepare a clean test device
To trigger a real install for testing:
- Use a phone that has never installed your app, or uninstall the app from the device.
- Reset the Google Advertising ID (
gps_adid): open Settings → Google → Ads → Google Advertising ID (or Reset advertising ID), then reset it. - Install and open the app again.
If you use an emulator, use an AVD image that includes Google Play. Emulators without Google Play cannot provide a valid Google Advertising ID.
You can find your Google Advertising ID (gps_adid) on the device under Settings → Google → Ads.
Test in the Adtrace panel
If you use the Adtrace panel:
- Copy your device Google Advertising ID (
gps_adid) from Settings → Google → Ads. - Open the Adtrace panel, select your app, then go to Settings → Testing Console.
- Enter the device ID, choose the ID type (
gps_adid), and check whether an install is recorded for that device.
If no install appears, review the earlier setup steps and the example apps, then try again on a clean device.
Test with logs (optional)
- Set log level to
verboseandenvironmenttoENVIRONMENT_SANDBOX. - Connect the device and filter Logcat with the
AdTracetag. - Uninstall, reset advertising ID if needed, reinstall, and open the app.
- In the server response logs, look for an
adidvalue. Receivingadidmeans the install was recorded successfully.
"adid" : "mhxd6or7d3u57fnbdy2r4urdrdxr7tlr"
9. Build your app for production
After you finish testing, update your AdTraceConfig before you ship the app:
- Adjust your log level so the SDK returns only the logs you need in production.
- Set
environmenttoAdTraceConfig.ENVIRONMENT_PRODUCTION.
- Java
- Kotlin
import io.adtrace.sdk.AdTrace;
import io.adtrace.sdk.AdTraceConfig;
import io.adtrace.sdk.LogLevel;
String appToken = "{YourAppToken}";
String environment = AdTraceConfig.ENVIRONMENT_PRODUCTION;
AdTraceConfig config = new AdTraceConfig(this, appToken, environment);
config.setLogLevel(LogLevel.WARN);
AdTrace.onCreate(config);
import io.adtrace.sdk.AdTrace
import io.adtrace.sdk.AdTraceConfig
import io.adtrace.sdk.LogLevel
val appToken = "{YourAppToken}"
val environment = AdTraceConfig.ENVIRONMENT_PRODUCTION
val config = AdTraceConfig(this, appToken, environment)
config.setLogLevel(LogLevel.WARN)
AdTrace.onCreate(config)
Sandbox and production traffic are separated in the Adtrace panel, so you can filter test data from real users.
You are ready to build and run your production app and start attributing users with the Adtrace SDK.
Checklist
Before you move on, confirm you have completed:
- Added the Adtrace SDK dependency
- Added Google Play Services Ads Identifier (Play Store apps)
- Added the Install Referrer library (Play Store apps)
- Declared required permissions in
AndroidManifest.xml - Added Proguard/R8 keep rules (if you use Proguard or R8)
- Initialized Adtrace in your
Applicationclass - Confirmed automatic lifecycle handling (SDK 3.0.0+; no manual
onResume/onPause) - Verified a successful install in Testing Console or logs
- Switched to
ENVIRONMENT_PRODUCTIONfor release
Next steps
Track user actions next: follow Event Tracking to send custom events from your Android app.