No description or website provided.
Clone or download
arun251 Version 2.5.2 (#55)
* Handling of `Future` returned by `LDClient.init()`
* `Date` HTTP header parsing specifies US locale
Latest commit 7949ef9 Sep 11, 2018

LaunchDarkly Android SDK

This library is compatible with Android SDK versions 15 and up (4.0.3 Ice Cream Sandwich)

How to use: Check out the included example app, or follow things here:

  1. Declare this dependency:

    compile 'com.launchdarkly:launchdarkly-android-client:2.5.2'
  2. In your application configure and initialize the client:

    LDConfig ldConfig = new LDConfig.Builder()
    LDUser user = new LDUser.Builder("user key")
    // NOTE: This method blocks for up to 5 seconds. See Javadoc or
    // for nonblocking options.
    LDClient ldClient = LDClient.init(this.getApplication(), ldConfig, user, 5);
  3. Evaluation example:

    variationResult = ldClient.stringVariation(flagKey, "fallback");
  4. Updating the User:

    LDUser updatedUser = new LDUser.Builder(user)

ProGuard Config

If you're using ProGuard add these lines to your config:

-keep class** { *; }
-keep class org.apache.http.** { *; }
-dontwarn okio.**
-dontwarn okhttp3.**
-dontwarn org.apache.http.**
-dontwarn org.slf4j.**
-dontwarn java.nio.file.*
-dontwarn javax.annotation.**
-dontwarn sun.misc.Unsafe
-dontwarn java.lang.ClassValue
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement

Feature Flag Updating

The LaunchDarkly Android SDK defaults to what we have found to be the best combination of low latency updates and minimal battery drain:

  1. When the app is foregrounded a Server-Sent Events streaming connection is made to LaunchDarkly. This streaming connection stays open as long as your app is in the foreground and is connected to the internet.
  2. When the app is backgrounded, the stream connection is terminated and the SDK will poll (with caching) for flag updates every 15 minutes.
  3. When the app is foregrounded, we fetch the latest flags and reconnect to the stream.
  4. In either the foreground or background, we don't try to update unless your device has internet connectivity.

This configuration means that you will get near real-time updates for your feature flag values when the app is in the foreground.

###Other Options If you prefer other options, here they are:

  1. Streaming can be disabled in favor of polling updates. To disable streaming call .setStream(false) on the LDConfig.Builder object.
  2. The default polling interval is 5 minutes. To change it call .setPollingIntervalMillis() on the LDConfig.Builder object.
  3. Background polling can be disabled (the app will only receive updates when the app is in the foreground). To disable background updating call .setDisableBackgroundUpdating(true) on the LDConfig.Builder object.
  4. The background polling interval can be adjusted (with the same minimum of 60 seconds). To change it call .setBackgroundPollingIntervalMillis() on the LDConfig.Builder object.

Example config with streaming disabled and custom polling intervals:

 LDConfig config = new LDConfig.Builder()
                .setPollingIntervalMillis(600_000) // 10 minutes
                .setBackgroundPollingIntervalMillis(3_600_000) // 1 hour

Known Issues/Features not yet implemented:

  • Make Android linter happy

Learn more

Check out our documentation for in-depth instructions on configuring and using LaunchDarkly. You can also head straight to the complete reference guide for this SDK or our Javadocs.


Much of the behavior we want to assert is around complicated device state changes such as app backgrounding, loss of internet connection. These are problematic to test in a programmatic way, so we rely on a combination of automated emulator tests and manual tests.

If, when running tests, the Android Studio build starts throwing countDebugDexMethods and countReleaseDexMethods errors using the run configuration dropdown, then switch to the command-line and exclude the two DEX methods causing the trouble.

./gradlew -x :launchdarkly-android-client:countDebugDexMethods -x :launchdarkly-android-client:countReleaseDexMethods -x :launchdarkly-android-client:signArchives --stacktrace clean build test cAT

About LaunchDarkly

  • LaunchDarkly is a continuous delivery platform that provides feature flags as a service and allows developers to iterate quickly and safely. We allow you to easily flag your features and manage them from the LaunchDarkly dashboard. With LaunchDarkly, you can:
    • Roll out a new feature to a subset of your users (like a group of users who opt-in to a beta tester group), gathering feedback and bug reports from real-world use cases.
    • Gradually roll out a feature to an increasing percentage of users, and track the effect that the feature has on key metrics (for instance, how likely is a user to complete a purchase if they have feature A versus feature B?).
    • Turn off a feature that you realize is causing performance problems in production, without needing to re-deploy, or even restart the application with a changed configuration file.
    • Grant access to certain features based on user attributes, like payment plan (eg: users on the ‘gold’ plan get access to more features than users in the ‘silver’ plan). Disable parts of your application to facilitate maintenance, without taking everything offline.
  • LaunchDarkly provides feature flag SDKs for
  • Explore LaunchDarkly