Skip to content

Instantly share code, notes, and snippets.

@reactivedroid
Created October 7, 2022 13:02
Show Gist options
  • Save reactivedroid/3b75bc7f269088d42272d149260dcad0 to your computer and use it in GitHub Desktop.
Save reactivedroid/3b75bc7f269088d42272d149260dcad0 to your computer and use it in GitHub Desktop.
Config file containing all the build configurations according to the supported environment
object Config {
object Flavor {
const val PROD = "prod"
const val STAGING = "staging"
}
const val HOST_URL = "HOST_URL"
const val SOME_KEY = "SOME_KEY"
// Supported flavors
val defaultFlavors = listOf(Flavor.PROD, Flavor.STAGING)
val keyList = listOf(
HOST_URL,
SOME_KEY
)
// Map of flavors with their respective configurations
val variantFieldMap = mapOf(
FLAOUR_STAGING to getStagingFields(),
FLAVOR_PROD to getProdFields()
)
object Staging {
const val host_url = "https://staging.api.com"
const val some_key = "staging_key"
// other configs can go here
}
object Prod {
const val host_url = "https://prod.api.com"
const val some_key = "prod_key"
// other configs can go here
}
private fun getStagingFields(): Map<String, String> {
val fields = mutableMapOf<String, String>()
fields[HOST_URL] = Staging.host_url
fields[SOME_KEY] = Staging.some_key
return fields
}
private fun getProdFields(): Map<String, String> {
val fields = mutableMapOf<String, String>()
fields[HOST_URL] = Prod.host_url
fields[SOME_KEY] = Prod.some_key
return fields
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment