Skip to content

Instantly share code, notes, and snippets.

@franhb
Forked from curioustechizen/UseApiKey.java
Created February 19, 2018 09:32
Show Gist options
  • Select an option

  • Save franhb/d4dc235fdcc71f2f48764fd09a7769f7 to your computer and use it in GitHub Desktop.

Select an option

Save franhb/d4dc235fdcc71f2f48764fd09a7769f7 to your computer and use it in GitHub Desktop.

Revisions

  1. @curioustechizen curioustechizen created this gist Apr 6, 2015.
    1 change: 1 addition & 0 deletions UseApiKey.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    String apiKey = BuildConfig.API_KEY
    11 changes: 11 additions & 0 deletions build.gradle
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    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']
    }
    1 change: 1 addition & 0 deletions secrets.properties
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    API_KEY=my_awesome_api_key