Skip to content

Instantly share code, notes, and snippets.

@kikermo
Last active August 11, 2017 16:33
Show Gist options
  • Save kikermo/040b371a376e2c1c26d3096cbd3886aa to your computer and use it in GitHub Desktop.
Save kikermo/040b371a376e2c1c26d3096cbd3886aa to your computer and use it in GitHub Desktop.
How to use a properties file to store keys instead of including them in build.gradle file
android {
...
def keys = new Properties()
file("../keys.properties").withInputStream {
stream -> keys.load(stream)
}
productFlavors {
development{
buildConfigField "String", "API_KEY", "\"" + keys.API_KEY_DEVELOPMENT + "\""
}
staging {
buildConfigField "String", "API_KEY", "\"" + keys.API_KEY_STAGING + "\""
}
production {
buildConfigField "String", "API_KEY", "\"" + keys.API_KEY_PRODUCTION + "\""
}
}
...
}
API_KEY_DEVELOPMENT = d3v3l0pm3ntKey
API_KEY_STAGING = st4gingk3y
API_KEY_PRODUCTION = pr0ducti0nK3y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment