Android SDK Reference

Updated 1 month ago by Archana Singh

This topic explains how to use the Harness Feature Flags SDK in your Android application. To learn more about using a sample Feature Flags SDK code with an Android application, see the Android GitHub repository.

The latest Android SDK (1.0.9) requires API level 19 or higher.

In this topic:

Before You Begin


  1. Create a feature flag in Harness. Feature flags wrap your code and allow you to manage the feature release in a controlled way. See Create a Feature Flag.
  2. Ensure that you have created your SDK Key. See Create an SDK Key.
  3. Download Harness Feature Flag Android Client SDK.
  4. An Android application to test your feature flag. If you do not have your Android Application, you can download a sample application from the Android SDK GitHub repository.

Use Harness Feature Flags SDKs with Android Applications

Perform the following steps to get started with using the Feature Flags SDK in your Android application:

Step 1: Declare the Repository

Add the following to your script in build.gradle file to declare the Maven Central repository for your build.

buildscript {
repositories {

Step 2: Add the Dependency to Your Application

Add the Harness Feature Flags Android SDK dependency in the build.gradle file.

Refer to the Harness Feature Flag Android client SDK to identify the latest version for your build automation tool. To know more about the fixes in the latest version of the SDK, see releases.

This section lists dependencies for Gradle (Short) and uses the 1.0.9 version.

implementation 'io.harness:ff-android-client-sdk:1.0.9'

Step 3: Authorize your Application to Connect to the Feature Flags Client

CfClient  is a base class that provides all features of SDK. This is a singleton and it is accessed with CfClient.getInstance().

val sdkConfiguration = CfConfiguration.builder()
.pollingInterval(60) //time in seconds

val target = Target().identifier("target")

CfClient.getInstance().initialize(context, "YOUR_API_KEY", sdkConfiguration, target)

  • YOUR_API_KEY: The SDK keys authorize your application to connect to the CF client. See Step 3: Create an SDK Key.
  • target: Represents the desired target for which the feature needs to be evaluated.

Step 4: Evaluate Target for Your Feature Flag

Once you have initialized the Harness Feature Flags client for a target, evaluate it for your feature flag. A feature flag is evaluated for a particular target.

Evaluation is performed based on the variation types. In case there is no evaluation with the provided ID, the default value is returned.

Boolean Variation

//get boolean evaluation
val evaluation: Boolean = CfClient.getInstance().boolVariation("demo_evaluation", false)

Number Variation

//get number evaluation
val numberEvaluation: Double = CfClient.getInstance().numberVariation("demo_number_evaluation", 0)

String Variation

//get string evaluaation
val stringEvaluation: String = CfClient.getInstance().stringVariation("demo_string_evaluation", "demo_value")

Step 5: Add the Method to Register for Events

This method provides a way to register a listener for different events that might be triggered by SDK, indicating a specific change in the SDK itself.

private final EventsListener eventsListener = statusEvent -> {
if (statusEvent.getEventType() == EVALUATION_CHANGE) {
Evaluation evaluation = statusEvent.extractPayload();


The triggered event will have one of the following types:

public enum EVENT_TYPE {

The following table provides a summary of the possible event types and corresponding responses.











When the listener is not needed, you can remove the desired listener from the internal list to avoid unexpected behavior.


When SDK is not needed, for example, when the app is not running, you can shut down the SDK. This can avoid potential memory leaks.


Step 6: Verify Your Feature Flag

Run the application from your IDE and verify whether the flag variation value displayed on your application page is consistent with the feature flag you created. Toggle the flag on and off to see whether your application is updated accordingly.

Sample Code for Android Application

Here is a sample code for using Harness Feature Flag SDKs with the Android application. To learn more about using the sample Android application, see the Android GitHub repository.

package com.example.ffsdktryout
import android.os.Bundle
import io.harness.cfsdk.*
import io.harness.cfsdk.logging.CfLog
import io.harness.cfsdk.CfClient
class MainActivity : AppCompatActivity() {
private val logTag = MainActivity::class.simpleName
private var eventsListener = EventsListener { event ->
if (event.eventType == StatusEvent.EVENT_TYPE.EVALUATION_CHANGE) {
// Do something
} else if (event.eventType == StatusEvent.EVENT_TYPE.EVALUATION_RELOAD) {
// Do something else
private val evaluationListener: EvaluationListener = EvaluationListener {
// Do something
override fun onCreate(savedInstanceState: Bundle?) {
val target = Target().identifier("YOUT_TARGET_IDENTIFIER").name("YOUR_TARGET_NAME")
val remoteConfiguration = CfConfiguration.builder()
) { _, result ->
if (result.isSuccess) {
val registerEventsOk = CfClient.getInstance().registerEventsListener(eventsListener)
var registerEvaluationsOk = CfClient.getInstance().registerEvaluationListener(
} else {
CfLog.OUT.e(logTag, "Init. error")

Please Provide Feedback