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

# Set up Android SDK

**Developer**

**Federal docs**

**EU docs**

**Federal docs**

> [!CAUTION]
>
> **LaunchDarkly onboarding is not available in federal environments**
>
> To learn more, read [LaunchDarkly in federal environments](https://launchdarkly.com/docs/home/infrastructure/federal).

Install and initialize the LaunchDarkly Android SDK to start evaluating feature flags in your application.

## Install the package

```groovy title="Groovy" lines wrap theme={null}
implementation 'com.launchdarkly:launchdarkly-android-client-sdk:5.+'
```

```kotlin title="Kotlin" lines wrap theme={null}
implementation("com.launchdarkly:launchdarkly-android-client-sdk:5.+")
```

The SDK uses [AndroidX from Jetpack](https://developer.android.com/jetpack/androidx). If your project does not use AndroidX,
read [Android's migration guide](https://developer.android.com/jetpack/androidx/migrate).

### Initialize the SDK for feature management

```kotlin title="Android SDK initialization" lines wrap theme={null}
import com.launchdarkly.sdk.*
import com.launchdarkly.sdk.android.*;
import com.launchdarkly.sdk.android.LDConfig.Builder.AutoEnvAttributes

// This is your mobile key.
val ldConfig = LDConfig.Builder(AutoEnvAttributes.Enabled)
    .mobileKey("YOUR_MOBILE_KEY")
    .build()

// A "context" is a data object representing users, devices, organizations, and other entities.
val context = LDContext.create("EXAMPLE_CONTEXT_KEY")

// If you don't want to block execution while the SDK tries to get
// latest flags, move this code into an async IO task and await on its completion.
val client: LDClient = LDClient.init(this@BaseApplication, ldConfig, context, 5)
```

### Initialize the SDK for feature management and Experimentation

If you want to use the LaunchDarkly [Experimentation](https://launchdarkly.com/docs/home/experimentation) feature, include a track call in your initialization code:

```kotlin title="Android SDK initialization for Experimentation" expandable lines wrap theme={null}
import com.launchdarkly.sdk.*
import com.launchdarkly.sdk.android.*
import com.launchdarkly.sdk.android.LDConfig.Builder.AutoEnvAttributes

// This is your mobile key.
val ldConfig = LDConfig.Builder(AutoEnvAttributes.Enabled)
    .mobileKey("YOUR_MOBILE_KEY")
    .build()

// A "context" is a data object representing users, devices, organizations, and other entities.
val context = LDContext.builder("EXAMPLE_CONTEXT_KEY")
    .set("email", "EXAMPLE_EMAIL")
    .build()

// If you don't want to block execution while the SDK tries to get
// latest flags, move this code into an async IO task and await on its completion.
val client: LDClient = LDClient.init(this@BaseApplication, ldConfig, context, 5)

// Call trackMetric when a metric action occurs in your app —
// a tap, a form submit, a screen view, a custom event, whatever your metric measures.
fun trackMetric(metricKey: String, data: LDValue = LDValue.ofNull()) {
    LDClient.get().trackData(metricKey, data)
}
```

> [accordion] Finding your SDK credentials
>
> You can find your server-side SDK keys, mobile keys, and client-side ID on the **SDK keys** page under **Settings**.

To learn more, read [Initialize the client](https://launchdarkly.com/docs/sdk/client-side/android#initialize-the-client) in the Android SDK reference guide.
