Remote config¶
KMPShip integrates Firebase Remote Config to allow you to dynamically change the behavior and appearance of your app without requiring users to download an update.
With Remote Config, you can:
- Enable or disable features remotely
- Customize app behavior for different audiences
- Roll out features gradually
- Experiment with A/B testing
Using Remote Config in KMPShip¶
KMPShip provides a structured and type-safe way to work with Remote Config values by categorizing them into Feature Flags and App Configuration Parameters.
Create your keys in Firebase Remote Config¶
Open your project in Firebase console and navigate to the Remote Config section:
Replace {yourProjectId}
with your actual Firebase project ID.
Here, you can define your keys and their default values.
Declare your keys in KMPShip¶
All keys defined in your Firebase Remote Config console must be added to the RemoteConfigKey
enum class:
enum class RemoteConfigKey(val value: String) {
EXAMPLE_BOOLEAN_KEY("my_boolean_key"),
EXAMPLE_STRING_KEY("my_string_key"),
}
Feature Flags (Boolean values)¶
Boolean Remote Config values are considered Feature Flags in KMPShip.
Steps to add a Feature Flag:¶
- Add a new value to the
FeatureFlag
enum class Location:com.example.myapp.domain.entity
- Add a mapping in the
RemoteConfigFeatureFlagModelMapper
class Location:com.example.myapp.data.source.firebase.remoteconfig.mapper
- Use
GetFeatureFlagUseCase
from your ViewModel Location:com.example.myapp.domain.usecase.settings
Example:¶
-
Define in Firebase Remote Config:
-
Update
RemoteConfigKey
enum class: -
Update
FeatureFlag
enum class: -
Update
RemoteConfigFeatureFlagModelMapper
mapper:class RemoteConfigFeatureFlagModelMapper : EntityToModelMapper<FeatureFlag, RemoteConfigModel> { override fun convertToModel(entity: FeatureFlag): RemoteConfigModel { val key = when (entity) { FeatureFlag.ONBOARDING_ENABLED -> RemoteConfigKey.ONBOARDING_ENABLED } return RemoteConfigModel(key = key) } }
-
Use in ViewModel:
App Configuration Parameters (Strings, Numbers, Arrays...)¶
All other Remote Config value types are considered general App Configuration Parameters.
Steps to add an App Configuration key:¶
- Add a value to the
AppConfiguration
data class Location:com.example.myapp.domain.entity
- Add mapping in
AppConfigurationRepositoryImpl
Location:com.example.myapp.data.repository
- Use
AppConfigurationRepository
to access the value Location:com.example.myapp.domain.usecase.config
(e.g.GetAppRatingAskPeriodMonthsUseCase
)
Example:¶
-
Define in Firebase Remote Config:
-
Update
RemoteConfigKey
enum class: -
Update
AppConfiguration
data class: -
Update
AppConfigurationRepositoryImpl
repository implementation:class AppConfigurationRepositoryImpl( private val localAppConfigurationDataSource: LocalAppConfigurationDataSource, private val remoteConfigDataSource: FirebaseRemoteConfigDataSource, ) : AppConfigurationRepository { override suspend fun getAppConfiguration(): AppConfigurationRepository.OutputParams.GetAppConfiguration { if (localAppConfigurationDataSource.appConfiguration == null) { val appRatingAskPeriodMonths = remoteConfigDataSource.getLong(key = RemoteConfigModel(key = RemoteConfigKey.APP_RATING_ASK_PERIOD_MONTHS).key.value, defaultValue = 3) localAppConfigurationDataSource.appConfiguration = AppConfiguration( appRatingAskPeriodMonths = appRatingAskPeriodMonths.toInt(), ) } return AppConfigurationRepository.OutputParams.GetAppConfiguration(appConfiguration = localAppConfigurationDataSource.appConfiguration!!) } }
-
Use in code:
Remote Config setup complete
You have successfully set up Remote Config in your KMPShip project. You can now manage feature flags and app configuration parameters dynamically through Firebase.