-
-
Save rahulgautam/0d1536979e122933bcb0 to your computer and use it in GitHub Desktop.
Android: Loading API Keys and other secrets from properties file using gradle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'] | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| API_KEY=my_awesome_api_key |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| String apiKey = BuildConfig.API_KEY |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment