Recent major versionsVersion 5 of the Android SDK introduces optional automatic collection of environment attributes. To learn more about upgrading, read Android SDK 4.x to 5.0 migration guide.
SDK quick linksLaunchDarkly’s SDKs are open source. In addition to this reference guide, we provide source, API reference documentation, and a sample application:
| Resource | Location |
|---|---|
| SDK API documentation | SDK API docs |
| Supported SDK Versions | Android SDK |
| GitHub repository | android-client-sdk |
| Sample application | Android |
| Published module | Maven |
SDK version compatibilityThe LaunchDarkly Android SDK is compatible with Android SDK versions 21 and higher (Android 5.0, Lollipop).
Get started
After you complete the Get started process, follow these instructions to start using the LaunchDarkly SDK in your Android application:Install the SDK
First, declare a dependency on the LaunchDarkly Android SDK. We recommend making the LaunchDarkly observability plugin available as well. This plugin collects and sends observability data to LaunchDarkly. This means you can review error monitoring and logs from within the LaunchDarkly UI. It requires the Android SDK version 5.9 or later. Here’s how:Using ProGuard or R8If you use ProGuard or R8, the
aar artifact should automatically include the configuration for the Android SDK. If this is not the case for your build, include the Proguard configuration lines from consumer-proguard-rules.pro into your proguard file.Import the SDK
Next, import the LaunchDarkly client in your application code:Initialize the client
After you install the SDK, create a single, shared instance ofLDClient. To create a client instance, you need your environment’s mobile key and the context for which you want to evaluate flags. This authorizes your application to connect to a particular environment within LaunchDarkly.
We recommend calling the client initialization method with a timeout of zero seconds. This allows you to use the client immediately. The app stores flags from the previous launch on the device and retrieves them for immediate use. The client connects in the background and continually updates itself with the latest flags.
Here’s how to create the client:
LDConfig.Builder.
Evaluate a flag
After you create theclient, you can use it to check which variation a particular context will receive for a feature flag.
Here’s how:
Shut down the client
Shut down the client when your application terminates. To learn more, read Shutting down.Data collection
The data collected by the Android SDK persists until the number of cached contexts exceeds a limit. When you callidentify, the number of cached contexts increments. Eventually, the number of cached contexts exceeds maxCachedContexts. When that happens, the SDK deletes context data in excess of maxCachedContexts, starting with the oldest context first.
To learn more, read Caching contexts to local storage.
Supported features
This SDK supports the following features:- SDK configuration, including
- Anonymous contexts and users
- Automatic environment attributes
- Caching contexts to local storage
- Context configuration
- Data saving mode
- Experimentation
- Flag variation evaluation
- Flag variation evaluation details
- Flushing events
- Getting all flags
- Hooks
- Identifying and changing contexts
- Logging configuration
- Monitoring SDK status
- Multiple environments
- Observability
- Offline mode
- Private attributes
- Relay Proxy configuration, using proxy mode
- Tracking custom events
- Shutting down
- Subscribing to flag changes