Android Compose: Firebase Remote Config

Andres Sandoval
2 min readAug 9, 2024

Tutorial shows how to add a feature flag using Firebase remote config. The app fetches a configuration flag at app startup from Firebase https://firebase.google.com/docs/remote-config. Can be use to do A/B testing.

Steps

  1. Create a new Firebase Project https://console.firebase.google.com
  2. Add google-services.json file to your project

3. Add the below dependencies to Android project and sync project

Inside the file build.gradle.kts(:app)

plugins {
..
id("com.google.gms.google-services")
}


android{
..
dependencies {
..
implementation (platform("com.google.firebase:firebase-bom:33.1.2"))
implementation("com.google.firebase:firebase-config-ktx")
implementation("com.google.firebase:firebase-analytics-ktx")
}
}

Inside the file build.gradle.kts(Project)

plugins {
..
id("com.google.gms.google-services") version "4.4.2" apply false
}

Firebase code example

@Composable
fun FirebaseRemoteConfig() {
val context = LocalContext.current
val remoteConfig: FirebaseRemoteConfig = Firebase.remoteConfig

remoteConfig.fetchAndActivate()
.addOnCompleteListener { task ->
if (task.isSuccessful) {
val gameData = Firebase.remoteConfig.getString("config")
Toast.makeText(context, "Fetch Success: $gameData", Toast.LENGTH_SHORT).show()…

--

--

No responses yet