2016-02-22 16:18:50 -08:00
|
|
|
def readDotEnv = {
|
|
|
|
def env = [:]
|
2016-03-03 13:32:32 -08:00
|
|
|
def envFile = System.env['ENVFILE'] ?: ".env"
|
2016-02-23 16:25:35 -08:00
|
|
|
println("Reading env from: $envFile")
|
2016-08-28 21:20:09 -04:00
|
|
|
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("**************************")
|
2016-02-22 16:18:50 -08:00
|
|
|
}
|
2016-02-23 16:25:35 -08:00
|
|
|
project.ext.set("env", env)
|
2016-02-22 16:18:50 -08:00
|
|
|
}
|
|
|
|
|
2016-02-23 16:25:35 -08:00
|
|
|
readDotEnv()
|
|
|
|
|
2016-02-22 16:18:50 -08:00
|
|
|
android {
|
|
|
|
defaultConfig {
|
2016-02-23 16:25:35 -08:00
|
|
|
project.env.each { k, v ->
|
2016-08-21 08:52:11 +09:00
|
|
|
def escaped = v.replaceAll("%","\\\\u0025")
|
2016-02-22 16:18:50 -08:00
|
|
|
buildConfigField "String", k, "\"$v\""
|
2016-08-21 08:52:11 +09:00
|
|
|
resValue "string", k, "\"$escaped\""
|
2016-02-22 16:18:50 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|