Skip to content

Instantly share code, notes, and snippets.

@danieldube1
Forked from curioustechizen/UseApiKey.java
Created November 10, 2016 08:13
Show Gist options
  • Select an option

  • Save danieldube1/f180257dc187bb0bee5db62215b6bc4d to your computer and use it in GitHub Desktop.

Select an option

Save danieldube1/f180257dc187bb0bee5db62215b6bc4d 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