Skip to content

Getting Started

kirich1409 edited this page May 18, 2026 · 1 revision

Getting Started

This page walks through the minimum steps to install Featured, declare one flag, and read its value. The whole thing fits in about 15 minutes.

1. Install the plugin and BOM

Add the repositories to settings.gradle.kts:

dependencyResolutionManagement {
    repositories {
        mavenCentral()
        google()
    }
}

Apply the Gradle plugin and declare dependencies in your app (or shared) module:

// build.gradle.kts
plugins {
    id("dev.androidbroadcast.featured") version "<version>"
}

dependencies {
    implementation(platform("dev.androidbroadcast.featured:featured-bom:<version>"))

    // Core runtime — always required
    implementation("dev.androidbroadcast.featured:featured-core")

    // Local persistence — DataStore is the recommended choice for Android
    implementation("dev.androidbroadcast.featured:featured-datastore-provider")
}

The latest version is available on Maven Central.

2. Declare a flag

Add a featured { } block to the same build.gradle.kts:

featured {
    localFlags {
        boolean("new_checkout", default = false) {
            description = "Enable the new checkout flow"
            category = "Checkout"
        }
    }
}

After syncing, the Gradle plugin generates:

  • internal object GeneratedLocalFlags with a ConfigParam<Boolean> property for new_checkout
  • A public extension function fun ConfigValues.isNewCheckoutEnabled(): Boolean

No further code is needed to declare the flag.

3. Wire ConfigValues with a provider

Create a ConfigValues instance once at app startup (e.g., in Application.onCreate or your DI graph):

import androidx.datastore.preferences.core.PreferenceDataStoreFactory
import dev.androidbroadcast.featured.ConfigValues
import dev.androidbroadcast.featured.datastore.DataStoreConfigValueProvider

val dataStore = PreferenceDataStoreFactory.create { context.dataStoreFile("feature_flags.preferences_pb") }

val configValues = ConfigValues(
    localProvider = DataStoreConfigValueProvider(dataStore),
)

4. Read the flag

One-shot read in a coroutine:

val isEnabled: Boolean = configValues.isNewCheckoutEnabled()

Reactive read in a ViewModel:

val isNewCheckoutEnabled: StateFlow<Boolean> =
    configValues.observe(GeneratedLocalFlags.newCheckout)
        .map { it.value }
        .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), false)

Next steps

The flag you just created is already eligible for dead-code elimination — see Release Optimization. With default = false, R8 will strip every code path behind isNewCheckoutEnabled() from your release APK without any additional configuration.

For the full artifact list (iOS, JVM, optional modules) see Installation.

Clone this wiki locally