2016-09-13 18:20:55 -07:00

31 lines
816 B
Groovy

def readDotEnv = {
def env = [:]
def envFile = System.env['ENVFILE'] ?: ".env"
println("Reading env from: $envFile")
try {
new File("$project.rootDir/../$envFile").eachLine { line ->
def (key, val) = line.tokenize('=')
if (key && val && key.substring(0, 1) != "#") {
env.put(key, val)
}
}
} catch (Exception ex) {
println("**************************")
println("*** Missing .env file ****")
println("**************************")
}
project.ext.set("env", env)
}
readDotEnv()
android {
defaultConfig {
project.env.each { k, v ->
def escaped = v.replaceAll("%","\\\\u0025")
buildConfigField "String", k, "\"$v\""
resValue "string", k, "\"$escaped\""
}
}
}