---
title: Unified SDK for Android
description: Reference for the Amplitude Unified SDK for Android.
product: analytics
token_estimate: 3196
---
# Unified SDK for Android

> For AI agents: a documentation index is available at [/docs/llms.txt](/docs/llms.txt). Append `.md` to any page URL for markdown, or send `Accept: text/markdown`.

The Amplitude Unified SDK for Android (`com.amplitude:unified-android`) bundles Analytics, Session Replay, and Experiment into one dependency and initializes them through a single entry point.

Use the Unified SDK when your Android app needs multiple Amplitude products with shared identity and configuration. Install the individual product SDKs instead when your app needs only one product or requires independent SDK instances.

The Unified SDK includes:

- [Analytics SDK (Android Kotlin SDK)](https://amplitude.com/docs/sdks/analytics/android/android-kotlin-sdk).
- [Experiment SDK](https://amplitude.com/docs/sdks/experiment-sdks/experiment-android).
- [Session Replay Android Plugin](https://amplitude.com/docs/sdks/session-replay/session-replay-android-plugin).

## Install the SDK

Add the dependency to your `build.gradle`:

```groovy
dependencies {
    implementation("com.amplitude:unified-android:1.0.0")
}
```

The SDK requires:

- minSdk 21 (Android 5.0 Lollipop) or higher.
- compileSdk 35 or higher.
- Kotlin 1.9 or higher.

The Unified SDK transitively includes Analytics (`analytics-android` 1.33.0), Session Replay 0.31.0, and Experiment 1.17.0. Don't add those SDKs separately.

## Initialize the SDK

Initialize the SDK before you instrument. Provide the API key for your Amplitude project.

#### Kotlin

```kotlin
val amplitude = AmplitudeUnified("API_KEY", applicationContext) {
    analytics {
        // Analytics-specific configuration — refer to the Android Kotlin SDK for all options
    }
    sessionReplay {
        sampleRate = 1.0
    }
    experiment {
        deploymentKey = "DEPLOYMENT_KEY"
    }
}
```

#### Java

```java
UnifiedConfigurationBuilder builder =
    new UnifiedConfigurationBuilder("API_KEY", context);
builder.getSessionReplay().setSampleRate(1.0);
builder.getExperiment().setDeploymentKey("DEPLOYMENT_KEY");

AmplitudeUnified amplitude = new AmplitudeUnified(builder);
```

## Configure the SDK

### Analytics configuration

The Unified SDK's analytics block accepts the same options as the Android Kotlin SDK's `Configuration`. For the full option list, refer to the [Android Kotlin SDK configuration section](https://amplitude.com/docs/sdks/analytics/android/android-kotlin-sdk#configure-the-sdk).

#### Kotlin

```kotlin
val amplitude = AmplitudeUnified("API_KEY", applicationContext) {
    analytics {
        flushQueueSize = 30
        flushIntervalMillis = 30000
        minTimeBetweenSessionsMillis = 300000
    }
}
```

#### Java

```java
UnifiedConfigurationBuilder builder =
    new UnifiedConfigurationBuilder("API_KEY", context);
builder.getAnalytics().setFlushQueueSize(30);
builder.getAnalytics().setFlushIntervalMillis(30000);
builder.getAnalytics().setMinTimeBetweenSessionsMillis(300000);

AmplitudeUnified amplitude = new AmplitudeUnified(builder);
```

### Experiment configuration

Experiment is enabled by default. Setting `enabled = false` disables Experiment; the `experiment` accessor then returns `null`. The `deploymentKey` defaults to the Analytics API key. The instance name, server zone, user, and exposure tracking all come from Analytics.

| Option | Type | Default | Description |
| --- | --- | --- | --- |
| `enabled` | Boolean | `true` | Disable Experiment by setting this to `false`. |
| `deploymentKey` | String? | `null` | Experiment deployment key. Falls back to the Analytics API key. |
| `config` | ExperimentConfig | `ExperimentConfig()` | Additional Experiment configuration. |

#### Kotlin

```kotlin
val amplitude = AmplitudeUnified("API_KEY", applicationContext) {
    experiment {
        deploymentKey = "DEPLOYMENT_KEY"
        config = ExperimentConfig()
    }
}
```

#### Java

```java
UnifiedConfigurationBuilder builder =
    new UnifiedConfigurationBuilder("API_KEY", context);
builder.getExperiment().setDeploymentKey("DEPLOYMENT_KEY");
builder.getExperiment().setConfig(new ExperimentConfig());

AmplitudeUnified amplitude = new AmplitudeUnified(builder);
```

### Session Replay configuration

Session Replay is enabled by default with a `sampleRate` of `0.0`, so nothing records until you set the sample rate. Setting `enabled = false` disables Session Replay; the `sessionReplay` accessor then returns `null`. For advanced configuration options, refer to the [Session Replay Android Plugin documentation](https://amplitude.com/docs/sdks/session-replay/session-replay-android-plugin).

| Option | Type | Default | Description |
| --- | --- | --- | --- |
| `enabled` | Boolean | `true` | Disable Session Replay by setting this to `false`. |
| `sampleRate` | Number | `0.0` | Fraction of sessions to capture (0.0–1.0). Set to `1.0` to capture all sessions. |
| `enableRemoteConfig` | Boolean | `true` | Enable remote configuration for Session Replay. |
| `serverUrl` | String? | `null` | Custom server URL. |
| `bandwidthLimitBytes` | Int? | `null` | Daily upload limit on metered networks. |
| `storageLimitMB` | Int? | `null` | Local storage limit in MB. |
| `privacyConfig` | PrivacyConfig | `PrivacyConfig()` | Privacy masking configuration. |
| `autoStart` | Boolean | `true` | Starts capture after plugin setup. |
| `recordLogOptions` | RecordLogOptions | `RecordLogOptions()` | Options for recording app logs into replays. |
| `captureWebViews` | Boolean | `false` | Capture WebView content. |

#### Kotlin

```kotlin
val amplitude = AmplitudeUnified("API_KEY", applicationContext) {
    sessionReplay {
        sampleRate = 1.0
        enableRemoteConfig = true
    }
}
```

#### Java

```java
UnifiedConfigurationBuilder builder =
    new UnifiedConfigurationBuilder("API_KEY", context);
builder.getSessionReplay().setSampleRate(1.0);
builder.getSessionReplay().setEnableRemoteConfig(true);

AmplitudeUnified amplitude = new AmplitudeUnified(builder);
```

## Use the SDK

`AmplitudeUnified` is the Analytics client and exposes the full [Android Kotlin SDK API](https://amplitude.com/docs/sdks/analytics/android/android-kotlin-sdk). It adds `sessionReplay` and `experiment` accessors, both nullable.

### Analytics

#### Kotlin

```kotlin
// Track an event
amplitude.track("Button Clicked", mapOf("button_id" to "sign_up"))

// Set user properties
val identify = Identify()
identify.set("plan", "premium")
amplitude.identify(identify)

// Set user ID
amplitude.setUserId("user@example.com")
```

#### Java

```java
// Track an event
Map<String, Object> props = new HashMap<>();
props.put("button_id", "sign_up");
amplitude.track("Button Clicked", props);

// Set user properties
Identify identify = new Identify();
identify.set("plan", "premium");
amplitude.identify(identify);

// Set user ID
amplitude.setUserId("user@example.com");
```

### Experiment

`AmplitudeUnified` initializes and configures the Experiment client when you create an instance. Access the client through the `experiment` property. Exposures track through Analytics. When Session Replay is recording and its device and session IDs match the event, the Session Replay plugin enriches the exposure event with `[Amplitude] Session Replay ID`.

#### Kotlin

```kotlin
val client = amplitude.experiment ?: return

// Fetch variants for the current user
client.fetch().get()

// Get a variant for a flag
val variant = client.variant("my-flag")
if (variant.value == "on") {
    // Flag is on
}
```

#### Java

```java
ExperimentClient client = amplitude.getExperiment();
if (client == null) return;

// Fetch variants for the current user
client.fetch().get();

// Get a variant for a flag
Variant variant = client.variant("my-flag");
if ("on".equals(variant.value)) {
    // Flag is on
}
```

### Session Replay

`AmplitudeUnified` initializes and configures Session Replay when you create an instance. Access the client through the `sessionReplay` property. Session Replay uses the Analytics device and session IDs; it doesn't store a user ID.

#### Kotlin

```kotlin
// Session Replay is automatically initialized and configured.

// Start (or resume) capture
amplitude.sessionReplay?.start()

// Stop (pause) capture. Call start() again to resume.
amplitude.sessionReplay?.stop()
```

#### Java

```java
// Session Replay is automatically initialized and configured.
com.amplitude.android.sessionreplay.SessionReplay sessionReplay = amplitude.getSessionReplay();

if (sessionReplay != null) {
    // Start (or resume) capture
    sessionReplay.start();

    // Stop (pause) capture. Call start() again to resume.
    sessionReplay.stop();
}
```

## Identity management

`AmplitudeUnified` synchronizes user identity across all Amplitude products. Identity and lifecycle changes forward to the owned plugins automatically:

- User ID changes update Experiment.
- Device ID, reset, opt-out, and session changes synchronize with Session Replay and Experiment.
- Session Replay uses the Analytics device and session IDs; it doesn't store a user ID.

#### Kotlin

```kotlin
// Propagates to all products
amplitude.setUserId("user@example.com")

// Propagates to all products
amplitude.setDeviceId("custom-device-id")

// Clears user ID and generates a new device ID
amplitude.reset()
```

#### Java

```java
// Propagates to all products
amplitude.setUserId("user@example.com");

// Propagates to all products
amplitude.setDeviceId("custom-device-id");

// Clears user ID and generates a new device ID
amplitude.reset();
```

## Debugging

To enable debug logging, set the log mode on the initialized instance:

#### Kotlin

```kotlin
val amplitude = AmplitudeUnified("API_KEY", applicationContext)
amplitude.logger.logMode = Logger.LogMode.DEBUG
```

#### Java

```java
AmplitudeUnified amplitude = new AmplitudeUnified(
    new UnifiedConfigurationBuilder("API_KEY", context));
amplitude.getLogger().setLogMode(Logger.LogMode.DEBUG);
```

## Common issues

### R8 reports missing optional provider classes

If R8 reports missing `org.conscrypt`, `org.bouncycastle`, or `org.openjsse` classes, add:

```groovy
implementation("com.squareup.okhttp3:okhttp:4.12.0")
```

Experiment 1.17.0 bundles OkHttp 4.9.1, which doesn't include R8 rules for optional TLS providers. OkHttp 4.12.0 adds those rules.

### Kotlin reports `Cannot access 'CoroutineScope'`

If Kotlin reports `Cannot access 'CoroutineScope'` when you call Session Replay members, add:

```groovy
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.9.0")
```

## Migration guide

If you use the individual Amplitude SDKs separately, follow these steps to migrate to the Unified SDK.

> **Warning:** Remove existing plugin registrations first
>
> Remove any existing `SessionReplayPlugin` and Experiment plugin registration and initialization before you add the Unified SDK. If a second Experiment plugin is added, the `experiment` accessor returns `null` because it can't select a unique client.

1. Replace the individual SDK dependencies with the Unified SDK in `build.gradle`.
2. Remove individual plugin registration and initialization code.
3. Replace your initialization code with Unified SDK initialization.

### Before migration

#### Kotlin

```kotlin
// Analytics SDK
val amplitude = Amplitude(
    Configuration(
        apiKey = "API_KEY",
        context = applicationContext,
    )
)

// Session Replay plugin
val sessionReplayPlugin = SessionReplayPlugin(context = applicationContext, sampleRate = 1.0)
amplitude.add(sessionReplayPlugin)

// Experiment SDK
val client = Experiment.initializeWithAmplitudeAnalytics(
    applicationContext, "DEPLOYMENT_KEY", ExperimentConfig()
)
client.fetch().get()
```

#### Java

```java
// Analytics SDK
Configuration configuration = new Configuration("API_KEY", context);
Amplitude amplitude = new Amplitude(configuration);

// Session Replay plugin
SessionReplayPlugin plugin = new SessionReplayPlugin(context, 1.0);
amplitude.add(plugin);

// Experiment SDK
ExperimentClient client = Experiment.initializeWithAmplitudeAnalytics(
    context, "DEPLOYMENT_KEY", new ExperimentConfig()
);
client.fetch().get();
```

### After migration

#### Kotlin

```kotlin
val amplitude = AmplitudeUnified("API_KEY", applicationContext) {
    sessionReplay {
        sampleRate = 1.0
    }
    experiment {
        deploymentKey = "DEPLOYMENT_KEY"
    }
}

amplitude.experiment?.fetch()?.get()
```

#### Java

```java
UnifiedConfigurationBuilder builder =
    new UnifiedConfigurationBuilder("API_KEY", context);
builder.getSessionReplay().setSampleRate(1.0);
builder.getExperiment().setDeploymentKey("DEPLOYMENT_KEY");

AmplitudeUnified amplitude = new AmplitudeUnified(builder);

ExperimentClient client = amplitude.getExperiment();
if (client != null) {
    client.fetch().get();
}
```

