Last active
May 4, 2017 00:17
-
-
Save igor-brishkoski/2d97afa867351a83e2a868cfea7d0898 to your computer and use it in GitHub Desktop.
Extract the keys from build.gradle
This file contains 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
//build.gradle | |
android{ | |
... | |
productFlavors{ | |
staging{ | |
//use in java code | |
buildConfigField "String", "SERVICE_THAT_I_NEED", getProps("service_secret_key") | |
buildConfigField "String", "MY_BACKEND_URL", getProps("my_url") | |
//use in xml, like AndroidManifest.xml | |
resValue "string", "google_maps_key", getProps("google_maps_key") | |
} | |
production{ | |
//use in java code | |
buildConfigField "String", "SERVICE_THAT_I_NEED", getProps("service_secret_key") | |
buildConfigField "String", "MY_BACKEND_URL", getProps("my_url") | |
//use in xml, like AndroidManifest.xml | |
resValue "string", "google_maps_key", getProps("google_maps_key") | |
} | |
} | |
} | |
//We're going to use this method to read the secrets that | |
//we stored in out secrets.properties file | |
def getProps(String propName) { | |
def propsFile = rootProject.file('secrets.properties') | |
if (propsFile.exists()) { | |
def props = new Properties() | |
props.load(new FileInputStream(propsFile)) | |
return props[propName] | |
} else { | |
return ""; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment