Set up Android SDK

Install the package

1implementation 'com.launchdarkly:launchdarkly-android-client-sdk:5.+'

The SDK uses AndroidX from Jetpack. If your project does not use AndroidX, read Android’s migration guide.

Initialize the SDK

Android SDK initialization
1import com.launchdarkly.sdk.*
2import com.launchdarkly.sdk.android.*;
3
4val ldConfig = LDConfig.Builder(AutoEnvAttributes.Enabled)
5 .mobileKey("YOUR_MOBILE_KEY")
6 .build()
7
8// A "context" is a data object representing users, devices, organizations, and other entities.
9val context = LDContext.create("EXAMPLE_CONTEXT_KEY")
10
11// If you don't want to block execution while the SDK tries to get
12// latest flags, move this code into an async IO task and await on its completion.
13val client: LDClient = LDClient.init(this@BaseApplication, ldConfig, context, 5)

You can find your server-side SDK key, client-side ID, and mobile key in the Environments section of your Project settings. Use the overflow menu next to the environment name to copy or display the needed key.

The environments list with the overflow menu open.

The Environments list with the overflow menu open.

To learn more, read Initialize the client in the Android SDK reference guide.