{"id":19149832,"url":"https://github.com/harness/ff-android-client-sdk","last_synced_at":"2025-05-07T04:44:53.538Z","repository":{"id":37798201,"uuid":"343499253","full_name":"harness/ff-android-client-sdk","owner":"harness","description":"Android SDK to integrate with Harness Feature Flag service","archived":false,"fork":false,"pushed_at":"2024-12-16T12:39:46.000Z","size":6388,"stargazers_count":3,"open_issues_count":0,"forks_count":9,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-05-07T04:44:47.439Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/harness.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-03-01T17:24:06.000Z","updated_at":"2025-01-16T13:11:46.000Z","dependencies_parsed_at":"2023-10-23T13:41:35.283Z","dependency_job_id":"c44ac4fa-bab4-4b9c-ad7c-0ffe44a3c077","html_url":"https://github.com/harness/ff-android-client-sdk","commit_stats":null,"previous_names":[],"tags_count":47,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harness%2Fff-android-client-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harness%2Fff-android-client-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harness%2Fff-android-client-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harness%2Fff-android-client-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/harness","download_url":"https://codeload.github.com/harness/ff-android-client-sdk/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252816520,"owners_count":21808702,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T08:09:46.313Z","updated_at":"2025-05-07T04:44:53.516Z","avatar_url":"https://github.com/harness.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"Android SDK for Harness Feature Flags\n========================\n\n## Table of Contents\n**[Intro](#Intro)**\u003cbr\u003e\n**[Requirements](#Requirements)**\u003cbr\u003e\n**[Quickstart](#Quickstart)**\u003cbr\u003e\n**[Further Reading](docs/further_reading.md)**\u003cbr\u003e\n**[Build Instructions](docs/build.md)**\u003cbr\u003e\n\n## Intro\n\nUse this README to get started with our Feature Flags (FF) SDK for Android. This guide outlines the basics of getting started with the SDK and provides a full code sample for you to try out.\n\nThis sample doesn’t include configuration options, for in depth steps and configuring the SDK, for example, disabling streaming or using our Relay Proxy, see the [Android SDK Reference](https://ngdocs.harness.io/article/74t18egxbi-android-sdk-reference).\n\nFor a sample FF Android SDK project, see [our test Android Project](https://github.com/harness/ff-android-client-sdk/tree/main/examples/GettingStarted).\n\n\n![FeatureFlags](docs/images/ff-gui.png)\n\n## Requirements\n\nTo use this SDK, make sure you've:\n\n- [Android Studio](https://developer.android.com/studio?gclid=CjwKCAjwp7eUBhBeEiwAZbHwkRqdhQkk6wroJeWGu0uGWjW9Ue3hFXc4SuB6lwYU4LOZiZ-MQ4p57BoCvF0QAvD_BwE\u0026gclsrc=aw.ds) or the [Android SDK](docs/dev_environment.md) for CLI only\u003cbr\u003e\n- [Java 11](https://www.oracle.com/java/technologies/downloads/#java11) or newer \u003cbr\u003e\n- [Gradle 8.3](https://gradle.org/releases/) or newer \u003cbr\u003e\n- Android Studio Hedgehog is needed to support Android Gradle Plugin 8.2.x when not building SDK source code from command line\n- Projects that consume this library will need Desugaring support enabled to support older phones. Please read https://developer.android.com/studio/write/java8-support#library-desugaring\n\nTo follow along with our test code sample, make sure you’ve:\n- [Created a Feature Flag](https://ngdocs.harness.io/article/1j7pdkqh7j-create-a-feature-flag) on the Harness Platform called harnessappdemodarkmode\n- Created a [server/client SDK key](https://ngdocs.harness.io/article/1j7pdkqh7j-create-a-feature-flag#step_3_create_an_sdk_key) and made a copy of it\n\n### Install the SDK\nYou can add the Android SDK to your application by adding the following snippet to root project's [build.gradle](https://github.com/harness/ff-android-client-sdk/blob/main/examples/GettingStarted/build.gradle#L2) file:\n```gradle\nbuildscript {\n    repositories {\n        mavenCentral()\n    }\n}\n```\n\nIn app module's [build.gradle](https://github.com/harness/ff-android-client-sdk/blob/main/examples/GettingStarted/app/build.gradle#L41) file add dependency for Harness's SDK\n\n`implementation 'io.harness:ff-android-client-sdk:2.1.0'`\n\n\n### Code Sample\nHere is a complete [example](https://github.com/harness/ff-android-client-sdk/blob/main/examples/GettingStarted/app/src/main/java/io/harness/cfsdk/gettingstarted/MainActivity.kt) that will connect to the feature flag service and report the flag value.  An event listener is registered\nto receive flag change events.\nAny time a flag is toggled from the feature flag service you will receive the updated value.\n\n```Kotlin\npackage io.harness.cfsdk.gettingstarted\n\nimport android.os.Bundle\nimport android.widget.TextView\nimport androidx.appcompat.app.AppCompatActivity\nimport android.util.Log\nimport ch.qos.logback.classic.android.BasicLogcatConfigurator\nimport io.harness.cfsdk.*\nimport io.harness.cfsdk.cloud.model.Target\nimport io.harness.cfsdk.cloud.sse.StatusEvent\n\n\nclass MainActivity : AppCompatActivity() {\n\n    private var flagName: String = BuildConfig.FF_FLAG_NAME.ifEmpty { \"harnessappdemodarkmode\" }\n\n    // The SDK API Key to use for authentication.  Configure it when installing the app by setting FF_API_KEY\n    // e.g. FF_API_KEY='my key' ./gradlew installDebug\n    private val apiKey: String = BuildConfig.FF_API_KEY\n\n        val client = CfClient()\n        client.use {\n            client.initialize(this, apiKey, sdkConfiguration, target)\n            client.waitForInitialization()\n            Log.i(\"SDKInit\", \"Successfully initialized client\")\n\n            // Get initial value of flag and display it\n            var flagValue: Boolean = client.boolVariation(flagName, false)\n            printMessage(\"$flagName : $flagValue\")\n\n            // Setup Listener to handle different events emitted by the SDK\n            client.registerEventsListener { event -\u003e\n                when (event.eventType) {\n                    // Setup Listener to handle flag change events.  This fires when a flag is modified.\n                    StatusEvent.EVENT_TYPE.EVALUATION_CHANGE -\u003e {\n                        Log.i(\"SDKEvent\", \"received ${event.eventType} event for flag\")\n                        event.extractEvaluationPayload()\n                        flagValue = client.boolVariation(flagName, false)\n                        printMessage(\"$flagName : $flagValue\")\n                    }\n                    else -\u003e Log.i(\"SDKEvent\", \"Got ${event.eventType.name}\")\n                }\n            }\n        }\n    }\n\n    // printMessage uses the UI Thread to update the text on the display\n    private fun printMessage(msg : String) {\n        val tv1: TextView = findViewById(R.id.textView1)\n        runOnUiThread { tv1.text = msg }\n    }\n}\n```\n\n### Running the example\nIf you want to run the [getting started example](examples/GettingStarted), then you can open the project in Android Studio.\nIf you would like to build, install and run the app from the CLI then follow these [steps to setup the SDK](docs/dev_environment.md).\n\nN.B this assumes you have set `$ANDROID_SDK` to the location where the Android SDK has been installed.\n\n\u003cbr\u003e\n\n#### Start the emulator\n```\n$ANDROID_SDK/emulator/emulator @Pixel_4.4_API_32\n```\n\u003cbr\u003e\n\n#### Build the project\n```shell\n./gradlew build -xtest\n```\n\u003cbr\u003e\n\n#### Install the Project\nYou must provide the FF_API_KEY which will be compiled in.\nYou can also optionally override the flag that will be evaluated\nby providing FF_FLAG_NAME\n```shell\nFF_FLAG_NAME=\"harnessappdemodarkmode\" FF_API_KEY=\u003cYOUR_API_KEY\u003e ./gradlew :examples:GettingStarted:installDebug\n```\n\u003cbr\u003e\nThe app should show the configured flags current value.  As you toggle the flag in the Harrness UI you will see the\nvalue update.\n\u003cbr\u003e\u003cbr\u003e\n\n![Alt Text](docs/images/android_sdk.gif)\n\n\u003cbr\u003e\n\n### Client Initialzation \nFor more information on initialzation options, see [Client Initialzation Options](docs/further_reading.md#client-initialization-options)\u003cbr\u003e\n\n\n### Release builds and ProGuard\nFor release builds, Android uses ProGuard to apply optimizations that can affect the behavior of the SDK.\n\nPlease add the following rule to your ProGuard configuration to ensure proper functionality when running your Android app from a release build\n\n```\n-keep class io.harness.cfsdk.** { *; }\n```\n\n### Running the example with docker\nYou will need to install the Android SDK in order to run the emulator, but if you wish to avoid installing Java, Gradle etc\nyou can use a docker image to compile and install the application to a locally running emulator.\nFollow the steps to [setup and run the emulator](docs/dev_environment.md).\n\nWith the emulator running build and install the app\n```shell\n# Build the code\ndocker run -v $(pwd):/app -v \"$HOME/.dockercache/gradle\":\"/root/.gradle\" -w /app mingc/android-build-box ./gradlew build\n\n# Install Debug build to emulator\ndocker run -v $(pwd):/app -v \"$HOME/.dockercache/gradle\":\"/root/.gradle\" -w /app mingc/android-build-box ./gradlew installDebug\n```\n\u003cbr\u003e\n\n### Additional Reading\n\nFurther examples and config options are in the further reading section:\n\n[Further Reading](docs/further_reading.md)\u003cbr\u003e\n[Getting Started Example](examples/GettingStarted)\u003cbr\u003e\n\n\n-------------------------\n[Harness](https://www.harness.io/) is a feature management platform that helps teams to build better software and to\ntest features quicker.\n\n-------------------------\n\n\n\n\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fharness%2Fff-android-client-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fharness%2Fff-android-client-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fharness%2Fff-android-client-sdk/lists"}