RemoteConfig is a Kotlin library that lets you manage all your remote configuration without requiring developers to manually download each configuration and integrate them into the Kotlin application.
You can have many configurations (messages, flags, server) on remote files, the library will do all the work for you.
Grab via Gradle:
repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'com.github.GiuseppeGiacoppo:RemoteConfig:LATEST_VERSION'
}
Retrieve a specific instance of RemoteResource for every configuration class
fun welcome() {
val remoteAppConfig = remoteConfig<AppConfig>()
val appConfig = remoteAppConfig.get()
println(appConfig.welcomeMessage)
}
You’re done. remoteAppConfig
will provide you the latest app configuration.
You need to setup each remote configuration with minimum effort. For each configuration, specify a remote repository and a local repository. The library will know where to fetch the configuration and where to store it locally.
fun main(args: Array<String>) {
initRemoteConfig {
remoteResource<AppConfig>(
storage("./configs"),
network("https://www.your.server/latest/appconfig.json")
)
remoteResource<MessagesConfig>(
// init other configs
)
}
}
Fetching is an async operation, this means it can take a while, and it can fail. It is possible to set a default configuration that will be marked as active if no more recent config is available.
val remoteAppConfig = remoteConfig<AppConfig>()
remoteAppConfig.setDefaultConfig(AppConfig("This is the default welcome message."))
Fetch the configuration every time you need, invoking fetch
method. Fresh configuration will be saved locally and you can activate it.
remoteAppConfig.fetch({
println("Fetch is successful")
remoteAppConfig.activateFetched()
}, {
println("Fetch is failed")
it.printStackTrace()
})
The configuration will be named by the configuration class name. You can have multiple configurations that share the same class by specifying a custom resource name
fun main(args: Array<String>) {
initRemoteConfig {
remoteResource<MessagesConfig>(
storage("./configs"),
network("https://www.your.server/latest/homemessages.json")
) {
resourceName = "home-messages"
}
remoteResource<MessagesConfig>(
storage("./configs"),
network("https://www.your.server/latest/detailmessages.json")
) {
resourceName = "detail-messages"
}
}
// you can then fetch, activate and use it
val homeMessages = remoteConfig<MessagesConfig>("home-messages")
val detailMessages = remoteConfig<MessagesConfig>("detail-messages")
}
RemoteConfig expects that each configuration is in json format. It supports also text format, and you can even create your own ResourceMapper
.
fun main(args: Array<String>) {
initRemoteConfig {
remoteResource<String>(
storage("./configs"),
network("https://www.your.server/latest/custom.txt")
) {
format = TextResourceMapper
}
}
}
git checkout -b my-new-feature
git commit -am 'Added some feature'
git push origin my-new-feature
RemoteConfig is an open source library inspired by Firebase Remote Config