Skip to content

Instantly share code, notes, and snippets.

@Kolyall
Last active November 1, 2018 08:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kolyall/5c9950b6da5153adfc056de9252e73be to your computer and use it in GitHub Desktop.
Save Kolyall/5c9950b6da5153adfc056de9252e73be to your computer and use it in GitHub Desktop.
Add buildConfigFields from .properties file via code

Add buildConfigFields from .properties file Create file in folder: D:\MyProject\app\properties\api\debug.properties

defaultConfig {
...
//region ---Adding properties/payment/release.properties KEYs to BuildConfig---
def paymentPropsFile = file('properties/api/debug.properties')
if (paymentPropsFile.canRead()) {
Properties properties = new Properties()
properties.load(new FileInputStream(paymentPropsFile))
for(String key : properties.stringPropertyNames()) {
def propertyValue = properties.getProperty(key)
def propertyParams = propertyValue.split(";")
buildConfigField "${propertyParams[0]}", "${key}", "${propertyParams[1]}"
}
} else {
throw new Exception("Could not read properties/api/debug.properties!")
}
//endregion
}
#Tue Sep 05 14:02:16 EEST 2017
API_VERSION=int;2
SECRET_PART=String;"AnyString"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment