Featurevisor

SDKs

Kotlin SDK

Featurevisor's Java SDK works directly in Kotlin and Android applications through normal JVM interoperability. You can use the same package and API without installing a separate Kotlin SDK.

Installation

The Featurevisor Java SDK is published through GitHub Packages. Add its repository to settings.gradle.kts:

dependencyResolutionManagement {
repositories {
mavenCentral()
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/featurevisor/featurevisor-java")
credentials {
username = providers.gradleProperty("gpr.user")
.orElse(providers.environmentVariable("GITHUB_ACTOR"))
.getOrElse("")
password = providers.gradleProperty("gpr.key")
.orElse(providers.environmentVariable("GITHUB_TOKEN"))
.getOrElse("")
}
}
}
}

GitHub Packages requires authentication. Add a GitHub username and a personal access token with the read:packages scope to ~/.gradle/gradle.properties:

gpr.user=YOUR_GITHUB_USERNAME
gpr.key=YOUR_GITHUB_TOKEN

Keep these credentials outside your project repository.

Add the SDK dependency to your application module's build.gradle.kts:

dependencies {
implementation("com.featurevisor:featurevisor-java:3.0.0")
}

Find the latest published version in Featurevisor Java packages.

Creating an instance

Load a datafile, parse it, and create a Featurevisor instance:

import com.featurevisor.sdk.DatafileContent
import com.featurevisor.sdk.Featurevisor
val datafileJson = "..." // load from your deployed datafile URL
val datafile = DatafileContent.fromJson(datafileJson)
val f = Featurevisor.createFeaturevisor(
Featurevisor.FeaturevisorOptions()
.datafile(datafile),
)

In an Android application, fetch and parse the datafile away from the main thread. Keep one Featurevisor instance for the appropriate application lifecycle instead of creating one for every evaluation.

Evaluating features

The Kotlin API provides the same flag, variation, and variable evaluations as the Java SDK:

val context = mapOf<String, Any>(
"userId" to "123",
"country" to "nl",
)
val enabled: Boolean = f.isEnabled("my_feature", context)
val variation: String? = f.getVariation("my_feature", context)
val message: String? = f.getVariableString(
"my_feature",
"welcome_message",
context,
)

Evaluation methods also use the context configured on the instance when no context argument is provided:

val enabled = f.isEnabled("my_feature")
val variation = f.getVariation("my_feature")
val message = f.getVariableString("my_feature", "welcome_message")

Call close() when the application lifecycle that owns the instance ends:

f.close()

See the Java SDK documentation for the complete API, including typed variables, datafile updates, diagnostics, events, modules, sticky values, and child instances. All of those APIs are available from Kotlin.

Android example

The Featurevisor Android example is written entirely in Kotlin. It shows how to fetch a deployed datafile, create the SDK instance, evaluate a flag, variation, and variable, and close the instance with the Android application lifecycle.

Previous
Java
Next
PHP