Skip to content

Instantly share code, notes, and snippets.

@rahulgautam
Forked from curioustechizen/UseApiKey.java
Created November 4, 2015 09:35
Show Gist options
  • Select an option

  • Save rahulgautam/0d1536979e122933bcb0 to your computer and use it in GitHub Desktop.

Select an option

Save rahulgautam/0d1536979e122933bcb0 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