react-native-config/android/dotenv.gradle

24 lines
535 B
Groovy

def readDotEnv = {
def env = [:]
def envFile = System.env['ENVFILE'] ?: ".env"
println("Reading env from: $envFile")
new File("$project.rootDir/../$envFile").eachLine { line ->
def (key, val) = line.tokenize('=')
if (key && val) {
env.put(key, val)
}
}
project.ext.set("env", env)
}
readDotEnv()
android {
defaultConfig {
project.env.each { k, v ->
buildConfigField "String", k, "\"$v\""
resValue "string", k, "\"$v\""
}
}
}