mirror of
https://github.com/zhigang1992/react-native-firebase.git
synced 2026-05-11 15:36:52 +08:00
- Implement ML-Kit Natural Language (#2117) - Includes additional refactor changes across other modules for internals api reworking
59 lines
1.7 KiB
Groovy
59 lines
1.7 KiB
Groovy
import groovy.json.JsonOutput
|
|
import groovy.json.JsonSlurper
|
|
|
|
String fileName = "firebase.json"
|
|
String jsonRoot = "react-native"
|
|
|
|
File jsonFile = null
|
|
File parentDir = rootProject.projectDir
|
|
|
|
for (int i = 0; i <= 3; i++) {
|
|
parentDir = parentDir.parentFile
|
|
jsonFile = new File(parentDir, fileName)
|
|
if (jsonFile.exists()) break
|
|
}
|
|
|
|
if (jsonFile != null && jsonFile.exists()) {
|
|
rootProject.logger.info ":${project.name} firebase.json found at ${jsonFile.toString()}"
|
|
Object json = null
|
|
|
|
try {
|
|
json = new JsonSlurper().parseText(jsonFile.text)
|
|
} catch (Exception ignored) {
|
|
rootProject.logger.warn ":${project.name} failed to parse firebase.json found at ${jsonFile.toString()}."
|
|
rootProject.logger.warn ignored.toString()
|
|
}
|
|
|
|
if (json && json[jsonRoot]) {
|
|
String jsonStr = JsonOutput.toJson(JsonOutput.toJson(json[jsonRoot]))
|
|
|
|
rootProject.ext.firebaseJson = [
|
|
raw: json[jsonRoot],
|
|
isFlagEnabled: { key ->
|
|
return json[jsonRoot] != null && json[jsonRoot][key] == true
|
|
}
|
|
]
|
|
|
|
rootProject.logger.info ":${project.name} found react-native json root in firebase.json, creating firebase build config"
|
|
android {
|
|
defaultConfig {
|
|
buildConfigField "String", "FIREBASE_JSON_RAW", jsonStr
|
|
}
|
|
}
|
|
} else {
|
|
rootProject.logger.info ":${project.name} firebase.json found with no react-native config, skipping"
|
|
android {
|
|
defaultConfig {
|
|
buildConfigField "String", "FIREBASE_JSON_RAW", '"{}"'
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
rootProject.logger.info ":${project.name} no firebase.json found, skipping"
|
|
android {
|
|
defaultConfig {
|
|
buildConfigField "String", "FIREBASE_JSON_RAW", '"{}"'
|
|
}
|
|
}
|
|
}
|