Feature Flags for Android Apps: Kotlin, Compose, Offline

Feature flags in an Android app: turn off a bad release without a Play Store update, target app versions, update Compose screens live and keep working offline.

  • android
  • kotlin
  • tutorials

An Android feature flag is a value your app reads at runtime to decide whether a feature is on, which variant a user gets, or how a screen behaves. The value comes from a server. Change it there and every installed copy of the app picks it up, with no new APK and no trip through Play review. A web app sheds a bad release with its next deploy. The Android build you shipped stays on people’s phones, sometimes for months, and the flags it reads are what you can still change from the dashboard.

This guide uses Kotlin and the Featureflip Android SDK, version 3.5.5, on API 26 and up. It walks through creating the client, reading flags from a ViewModel and Jetpack Compose, targeting app versions, cold starts and offline use, tests, the OpenFeature provider, a comparison with Firebase Remote Config, and retiring flags that old builds still read.

Key Takeaways

  • Halting a staged rollout on Google Play stops new installs of the update, and people who already have it keep it. A flag switches the feature off on their phones too, the next time the app receives a flag update.
  • Create one FeatureflipClient per process in Application.onCreate() and run initialize() off the main thread. From then on every boolVariation call is a synchronous in-memory read, safe inside a composable.
  • Compose won’t redraw by itself when a flag changes. Push changes from onUpdate into a StateFlow in your ViewModel, and read once more after initialization finishes.
  • Send app_version in the context, and a semver rule can switch a feature off for one broken build while every other version keeps it.
  • The default value in your code is compiled into the APK. A fresh install sees it offline, and every old build falls back to it once the flag is archived, so make it the safe value.

1. Why a shipped Android release is hard to take back

Fix a bug in a web app, deploy, and the next page load runs the fixed code. There is one version in production. A mobile app has as many versions in production as your users have installed, and none of them are yours to change once they leave the store.

Google Play’s staged rollouts cover part of this. You release to 5% of users, watch the crash rate in Android vitals, and halt if it climbs. Play’s own help page is blunt about the limit: “Users who already received the app version in your staged rollout version will remain on that version.” Getting a fix to them takes a new release through review, followed by a wait while each phone installs it. One with auto-update switched off may hold out for months.

A flag check around the risky code reaches those phones. The code is already on the device. Whether it runs depends on a value from the server, so turning the flag off reaches every install that reads it, the halted build included. The kill switch use case covers the pattern in more detail.

Who still runs a broken feature after each response Three horizontal bars over time, each showing the share of installs that already updated to a broken release. Halting the staged rollout leaves the whole bar red, because those users keep the broken version. Shipping a fixed release turns the bar green in steps, as each user updates. Turning a flag off turns the whole bar green at once, on the next flag update. Who still runs the broken feature after you respond Illustrative: installs that already took the bad update, from the moment you act Halt the staged rollout They keep the broken version Ship a fixed release Review Fixed as each user updates Turn the flag off Off on every install that reads the flag You act Weeks later
Illustrative. The flag bar assumes the broken code path checks the flag before it runs.

A flag can only switch code that checks it. A crash in Application.onCreate(), before any flag is read, still needs a fixed release, and so does a bug in code you never wrapped. Put the check at the entry to the new code path.


2. Add the SDK and create one client

The SDK is on Maven Central. Add it to the app module’s build.gradle.kts:

dependencies {
implementation("io.featureflip:featureflip-android:3.5.5")
// Optional: lets the SDK pause streaming while the app is in the background
implementation("androidx.lifecycle:lifecycle-process:<version>")
}

Minimums are API 26 and Java 17, plus Kotlin 2.3 if the app is written in Kotlin (Java-only apps skip the Kotlin plugin). R8 and ProGuard need no keep rules for it, since the library has bundled its own since 3.3.0.

Create the client in your Application class. It holds a streaming connection, a disk cache, an event queue and a lifecycle observer, which is why you want exactly one per process, and FeatureflipClient.get() enforces it: a second call with the same key returns a handle to the same shared client, so a stray call from an Activity opens no second connection.

class MyApp : Application() {
private val appScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
lateinit var flags: FeatureflipClient
private set
lateinit var flagsReady: Deferred<Unit>
private set
override fun onCreate() {
super.onCreate()
flags = FeatureflipClient.get(
FeatureflipConfig(
clientKey = "your-client-sdk-key",
context = mapOf("app_version" to BuildConfig.VERSION_NAME),
applicationContext = this,
),
)
flagsReady = appScope.async { flags.initialize() }
}
}

initialize() makes a network request and can wait up to initTimeoutMs, 10 seconds by default. Run it on Dispatchers.IO. Called on the main thread, it blocks the UI and can trigger an ANR.

Use a client SDK key. Only flags marked client-side visible reach the app, and the targeting rules themselves stay on the server, so nothing about who gets what ships inside your APK.

Pass applicationContext as well. With it, the SDK saves the ID it generates for a signed-out user in SharedPreferences, and that user stays in the same rollout bucket across restarts. Leave it out and the ID is new on every cold start.

AGP 8.0 and later skip generating BuildConfig unless you ask for it, so if BuildConfig.VERSION_NAME won’t resolve, add buildFeatures { buildConfig = true } to the android block. The Android quickstart covers the same setup step by step.


3. Read flags from a ViewModel and Jetpack Compose

Every typed read (boolVariation, stringVariation, numberVariation, jsonVariation) comes straight out of an in-memory snapshot. No suspend function, nothing to await. Call them from a composable, a click handler or a ViewModel.

val showBanner = flags.boolVariation("new-banner", false)
val buttonColor = flags.stringVariation("button-color", "blue")

Compose won’t redraw on its own when a flag changes, though. It recomposes when observed state changes, and a flag value isn’t Compose state, so someone sitting on the checkout screen keeps the old branch after you flip the flag. To make the screen react, subscribe with onUpdate and push the value into a StateFlow:

class CheckoutViewModel(
private val flags: FeatureflipClient,
private val flagsReady: Deferred<Unit>,
) : ViewModel() {
private val _newCheckout = MutableStateFlow(read())
val newCheckout: StateFlow<Boolean> = _newCheckout.asStateFlow()
private val unsubscribe = flags.onUpdate { keys ->
if ("new-checkout" in keys) _newCheckout.value = read()
}
init {
viewModelScope.launch {
flagsReady.await()
_newCheckout.value = read()
}
}
private fun read() = flags.boolVariation("new-checkout", false)
override fun onCleared() = unsubscribe()
}
@Composable
fun CheckoutScreen(viewModel: CheckoutViewModel) {
val newCheckout by viewModel.newCheckout.collectAsStateWithLifecycle()
if (newCheckout) NewCheckout() else LegacyCheckout()
}

The init block is there because onUpdate fires for changes that arrive after the first load, and the first load itself doesn’t fire it. On a cold start the ViewModel can easily exist before initialize() finishes, read the default, and then hear nothing when the real value lands. Awaiting flagsReady and reading again closes that hole.

Listeners run on the SDK’s own background thread. Fine for a StateFlow. A View has to change on the main thread, so if you redraw one directly from the listener, post to the main thread first.

After a login, call identify() with the new user’s attributes. It fetches that user’s flags before it returns, so it belongs on Dispatchers.IO too, and when it finishes onUpdate fires for every flag whose value changed.

suspend fun onSignedIn(user: User) = withContext(Dispatchers.IO) {
flags.identify(
mapOf(
"user_id" to user.id,
"plan" to user.plan,
"app_version" to BuildConfig.VERSION_NAME,
),
)
}

identify() replaces the whole context. Carry app_version over, or your version rules stop matching after sign-in.


4. Target app versions with semver rules

Several builds of your app are in production at once, so a rule can target a build as easily as a user.

Take a 4.1.0 release whose new photo picker crashes on some devices, fixed in 4.1.1 while a good share of your users are still on 4.1.0. Add a rule to the new-photo-picker flag with app_version Semver Equals 4.1.0, serving false. The picker disappears for that one build. People on 4.1.1 and later keep it, and once 4.1.0 has faded out of your install base you delete the rule.

It works in the other direction as well. Say a feature depends on an API change that only 4.3.0 and newer handle correctly. Put the rollout on a rule of app_version Semver Greater Than or Equal 4.3.0, leave the default rule serving false, and older builds stay off however far the rollout goes.

Send the version name, like 4.1.0. A semver rule fed the version code, a bare build number like 41000, matches nothing at all and gives no error, and that exact mix-up has a troubleshooting page. Rules, segments and percentage rollouts otherwise behave as they do on any platform, documented in targeting and segments.


5. Cold starts, offline and the background

Someone opens your app on a train in a tunnel.

The disk cache. Each batch of values the SDK receives gets written to a file in your app’s cache directory. initialize() loads that file before it goes to the network, so a returning user who opens the app in airplane mode gets whatever they had at their last sync, while the stream retries in the background and catches up once there’s signal.

The code default. A fresh install with no connection has no cache. Every read returns the default you passed, and so does any read that runs before initialize() has loaded the cache. That default ships inside the APK and is what every old build serves after the flag is archived, so for a new or risky feature, make it off.

The background. Add androidx.lifecycle:lifecycle-process and the SDK closes its stream and flushes queued events when the app is backgrounded, then reconnects when it comes back. You write no lifecycle code for this, and we’d add the dependency to every app that uses the SDK. Without that dependency the SDK has no way to know the app left the foreground, and the stream stays open for as long as the process lives.

While connected, changes arrive over server-sent events within moments. If your network setup prefers polling, streaming = false switches to a fetch every pollIntervalMs. The reliability guide covers what the SDKs do if Featureflip itself has an outage, and the outage recovery post tells the longer version.


6. Test both branches

A boolean flag gives a screen two branches to test. FeatureflipClient.forTesting() returns a client with fixed values that never touches the network and is already initialized when you get it.

class CheckoutViewModelTest {
@Before fun setUp() = Dispatchers.setMain(UnconfinedTestDispatcher())
@After fun tearDown() = Dispatchers.resetMain()
@Test fun showsNewCheckoutWhenFlagIsOn() {
val flags = FeatureflipClient.forTesting(mapOf("new-checkout" to true))
val viewModel = CheckoutViewModel(flags, CompletableDeferred(Unit))
assertTrue(viewModel.newCheckout.value)
}
@Test fun keepsLegacyCheckoutWhenFlagIsMissing() {
val flags = FeatureflipClient.forTesting(emptyMap())
val viewModel = CheckoutViewModel(flags, CompletableDeferred(Unit))
assertFalse(viewModel.newCheckout.value)
}
}

Keep the missing-flag test. It covers the default, the exact branch a fresh install takes offline. Live updates need a staging environment. Test clients never call onUpdate listeners.


7. Using OpenFeature on Android

If your team codes against OpenFeature, the CNCF’s vendor-neutral flag API, use io.featureflip:featureflip-android-openfeature (0.1.2), which pulls in the Android SDK and the OpenFeature Kotlin SDK for you.

appScope.launch {
OpenFeatureAPI.setProviderAndWait(
FeatureflipProvider(
FeatureflipConfig(
clientKey = "your-client-sdk-key",
applicationContext = applicationContext,
),
),
initialContext = ImmutableContext(targetingKey = "user-42"),
)
val enabled = OpenFeatureAPI.getClient().getBooleanValue("new-checkout", false)
}

Set the provider once, in Application. Inside an Activity, every screen rotation recreates the Activity and runs the setup a second time, fetching every flag again while the old provider shuts down. User switching, reason mapping and type rules on Android are in the OpenFeature integration docs.


8. Firebase Remote Config or a flag service?

If your app already ships Firebase, Remote Config comes with it at no cost. For remote values in one app, it works. Its default minimum fetch interval is 12 hours, and Firebase describes anything shorter as a development setting. Real-time updates, available from Android SDK 21.3.0 once you register a listener, skip that interval and hold a connection open while the app is in the foreground.

Things change when a flag gates more than the Android app. A checkout flag can gate code in the backend, the web app and iOS as well. With Featureflip all of them read the same flag from one dashboard with one audit log, and for a given user the Android app gets the value the server SDKs would compute, since the evaluation engine and the SDKs are tested against one shared set of test vectors. Change reasons and stale-flag detection work the same for each of them.

Client-side flags also run on every device, so pricing per monthly active user grows with your installs. Featureflip’s plans are flat-priced with unlimited evaluations, and the price is set by the plan you pick, whatever your install count. Numbers are on the pricing page.


9. Retire flags that old builds still read

Delete a flag check from your next Android release and every older build on people’s phones keeps running it. Archive the flag too soon and those builds fall back to the default in their code. For a feature at 100%, that default is usually the off value, so an early archive switches a finished feature off for everyone who hasn’t updated.

Since 3.3.0 the SDK reports which flags the app reads, about once an hour per device and again on each return to the foreground. Reads from old installs keep the flag off the no-traffic list in stale-flag detection. They also make Featureflip refuse to archive it, since it can still see the flag being evaluated. The flag cleanup Action opens a pull request that removes a dead flag from Kotlin or Java code, and its archive step hits that same refusal. With an app you can’t update remotely, the refusal can hold for months. The Action’s docs say as much and leave the archive to you, once the old versions are gone.

So ship the release without the flag, watch the reads fall in the flag’s analytics as people update, and archive when they reach zero. An in-app update prompt with a minimum supported version shortens the wait.


The shorter version

Play can halt a staged rollout, but phones that already took the update keep it, and a flag check is how you switch the feature off on them. Add io.featureflip:featureflip-android, create one client in Application.onCreate() with a client key, and call initialize() on Dispatchers.IO. Reads are synchronous after that. For Compose, push onUpdate changes into a StateFlow and read again once initialization finishes. Send app_version so semver rules can single out a build. Offline, returning users get cached values and a fresh install gets your code default. Test both branches with forTesting, and archive a flag after the builds that read it have aged out.


Frequently asked questions

How do I add feature flags to an Android app?

Add io.featureflip:featureflip-android to your app module’s Gradle dependencies. In Application.onCreate(), create a client with FeatureflipClient.get(FeatureflipConfig(clientKey = "your-client-sdk-key", applicationContext = this)) and call initialize() from a background coroutine. Read flags anywhere with flags.boolVariation("flag-key", false). The key has to be a client SDK key and each flag has to be marked client-side visible in the dashboard, or the app only ever sees the default.

Can I turn off a feature in an Android app without a Play Store update?

Yes, if the feature’s code checks a flag. Turn the flag off in the dashboard and every installed copy that reads it switches over on its next update from the server, which over the streaming connection takes moments. Halting a staged rollout on Google Play can’t do that, because users who already received the update keep it. Code that crashes before it reaches the flag check still needs a fixed release, so put the check at the start of the new code path.

Do feature flags work offline on Android?

For returning users, yes. The SDK writes the last values it received to a file in the app’s cache directory and loads them on the next launch before going to the network, so an app opened in airplane mode serves its last synced values. A user who has never synced, such as a fresh install with no connection, gets the default value from your code. Pick defaults that are safe with no server at all.

How do I use feature flags in Jetpack Compose?

You can read a flag inside a composable, since reads are synchronous, but the composable won’t redraw when the flag changes. Hold the value in a StateFlow in your ViewModel, update it from the client’s onUpdate listener, and collect it in the composable with collectAsStateWithLifecycle(). Read the flag once more after initialize() finishes too, because the first load doesn’t fire onUpdate.

Is Firebase Remote Config a feature flag tool?

It can serve as one. Remote Config delivers remote values to Android apps, supports conditions and percentages, and is free with Firebase. Its default minimum fetch interval is 12 hours, and newer SDKs add real-time updates through a listener. A dedicated flag service fits better once the same flag has to agree across your backend, web and mobile apps, or when you want an audit log, change reasons and stale-flag detection on every flag.

Does Featureflip support OpenFeature on Android?

Yes. The io.featureflip:featureflip-android-openfeature provider connects the OpenFeature Kotlin SDK to Featureflip. Set it once in your Application with OpenFeatureAPI.setProviderAndWait(FeatureflipProvider(config)), then read flags through OpenFeatureAPI.getClient(). The OpenFeature docs cover the full setup.


Featureflip is a flat-priced feature flag platform, and the source of its Android SDK is on GitHub. You can start on the Free plan without a credit card and follow the Android quickstart to get a first flag onto a test device in about five minutes.