Chapter 10 · Firebase Remote Config Basics
Subchapter 10.1
references/android_setup.mdMarkdown3 KBView on GitHub
Important references:
firebase-basics skills, particularly those for project and app
setup, before proceeding.Before you begin, ensure you have the following. If a google-services.json
file is present, then use that Firebase project and app. Otherwise you may need
to create them.
firebase-basics).npx -y firebase-tools@latest projects:create (see firebase-basics).npx -y firebase-tools@latest apps:create <IOS|ANDROID|WEB> <package-name-or-bundle-id>The google-services.json file must be present in the Android app’s module
directory. If missing, get the config using the Firebase CLI:
npx -y firebase-tools@latest apps:sdkconfig ANDROID <App-ID>.
These changes are made to your Android project’s Gradle files. Google Analytics is highly recommended as it enables conditional targeting based on user properties and audiences.
Ensure the Google Services plugin is in the plugins block:
plugins {
// ... other plugins
id("com.google.gms.google-services") version "4.4.0" apply false
}Add the Google Services plugin to the plugins block:
plugins {
// ... other plugins
id("com.google.gms.google-services")
}Add the Firebase Remote Config and Analytics dependencies. Using the Firebase Bill of Materials (BoM) is the best practice for version management.
dependencies {
// ... other dependencies
// Import the Firebase BoM
implementation(platform("com.google.firebase:firebase-bom:32.7.0"))
// Add the dependencies for Remote Config and Analytics
implementation("com.google.firebase:firebase-config-ktx")
implementation("com.google.firebase:firebase-analytics-ktx")
}The following steps cover the essential patterns for using Remote Config effectively.
Define default values so your app has functional logic before it ever fetches a
template from the server. Create an XML file (e.g.,
res/xml/remote_config_defaults.xml):
xml <!-- Example Remote Config Defaults File --> <?xml version="1.0" encoding="utf-8"?> <defaultsMap> <entry> <key>welcome_message</key> <value>Welcome to the app!</value> </entry> <entry> <key>is_feature_enabled</key> <value>false</value> </entry> </defaultsMap>
Then, initialize the SDK in your Activity or Application class:
```kotlin
val remoteConfig = Firebase.remoteConfig
remoteConfig.setDefaultsAsync(R.xml.remote_config_defaults)
```To apply values from the cloud, you must fetch them and then activate them.
kotlin remoteConfig.fetchAndActivate() .addOnCompleteListener(this) { task -> if (task.isSuccessful) { val updated = task.result println("Config params updated: $updated") } else { println("Fetch failed") } // Access a value val message = remoteConfig.getString("welcome_message") }