[gradle Flavors 切换]
This commit is contained in:
yangyakun
2024-04-10 18:57:23 +08:00
parent 4fa9d64fa6
commit 5c624c1943
5 changed files with 138 additions and 330 deletions

View File

@@ -1,3 +1,67 @@
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
/**
* 读取各车型宣传视频本地配置
* @param env
* @return
*/
Object readMediaUrlConfigFromJsonFile(env){
try {
// 加载config.json 文件
File file = new File("${rootDir}/app/config/MediaUrlConfig.json")
def jsonSlurper = new JsonSlurper()
// 解析json
def config = jsonSlurper.parse(file)
def flavorNames = variantVehicleName()
def jsonOutput = new JsonOutput()
def getKey = flavorNames
config.get(env).each {key, value ->
// 匹配flavor对应的 json
println "--------${flavorNames.toLowerCase()}---------${key}"
if(flavorNames.toLowerCase().contains(key)){
getKey = key
return true
}
}
return jsonOutput.toJson(config.get(env).get(getKey))
} catch (IOException e) {
e.printStackTrace()
}
return null
}
/**
* 读取各车型宣传视频本地配置
* @param env
* @return
*/
Object readMusicUrlConfigFromJsonFile(env){
try {
// 加载config.json 文件
File file = new File("${rootDir}/app/config/MusicUrlConfig.json")
def jsonSlurper = new JsonSlurper()
// 解析json
def config = jsonSlurper.parse(file)
def flavorNames = variantVehicleName()
def jsonOutput = new JsonOutput()
def getKey = flavorNames
config.get(env).each {key, value ->
// 匹配flavor对应的 json
if(flavorNames.toLowerCase().contains(key)){
getKey = key
return true
}
}
return jsonOutput.toJson(config.get(env).get(getKey))
} catch (IOException e) {
e.printStackTrace()
}
return null
}
boolean isCurrentDriver(String flavors) {
if(isDriver() && isCurrentFlavors(flavors)){
return true
@@ -48,4 +112,6 @@ ext {
isCurrentFlavors = this.&isCurrentFlavors
isCurrentDriver = this.&isCurrentDriver
isCurrentPassenger = this.&isCurrentPassenger
readMediaUrlConfigFromJsonFile = this.&readMediaUrlConfigFromJsonFile
readMusicUrlConfigFromJsonFile = this.&readMusicUrlConfigFromJsonFile
}