Skip to content

Instantly share code, notes, and snippets.

@emedinaa
Forked from curioustechizen/UseApiKey.java
Created February 6, 2017 19:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emedinaa/fcdbe924f864125e1b2e7c8407691b4d to your computer and use it in GitHub Desktop.
Save emedinaa/fcdbe924f864125e1b2e7c8407691b4d to your computer and use it in GitHub Desktop.
Android: Loading API Keys and other secrets from properties file using gradle
buildTypes {
applicationVariants.all { variant ->
variant.buildConfigField "String", "API_KEY", "\""+getApiKey()+"\""
}
}
def getApiKey(){
def Properties props = new Properties()
props.load(new FileInputStream(new File('secrets.properties')))
return props['API_KEY']
}
API_KEY=my_awesome_api_key
String apiKey = BuildConfig.API_KEY
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment