[6.4.0]
[gradle Flavors 切换]
This commit is contained in:
48
app/script/projectFlavors/project.gradle
Normal file
48
app/script/projectFlavors/project.gradle
Normal file
@@ -0,0 +1,48 @@
|
||||
apply from: "./script/utils.gradle"
|
||||
|
||||
|
||||
project.android.productFlavors {
|
||||
mogo {
|
||||
dimension "project"
|
||||
buildConfigField 'boolean', 'secure', "true"
|
||||
buildConfigField 'String', 'URLs', "\"${readFileToJson("mogo").replace("\"", "\\\"")}\""
|
||||
buildConfigField 'String', 'mediaUrlConfig', "\"${readMediaUrlConfigFromJsonFile("mogo").replace("\"", "\\\"")}\""
|
||||
buildConfigField 'String', 'musicUrlConfig', "\"${readMusicUrlConfigFromJsonFile("mogo").replace("\"", "\\\"")}\""
|
||||
}
|
||||
yantai {
|
||||
dimension "project"
|
||||
buildConfigField 'boolean', 'secure', "false"
|
||||
buildConfigField 'String', 'URLs', "\"${readFileToJson("yantai").replace("\"", "\\\"")}\""
|
||||
buildConfigField 'String', 'mediaUrlConfig', "\"${readMediaUrlConfigFromJsonFile("yantai").replace("\"", "\\\"")}\""
|
||||
buildConfigField 'String', 'musicUrlConfig', "\"${readMusicUrlConfigFromJsonFile("yantai").replace("\"", "\\\"")}\""
|
||||
}
|
||||
|
||||
dali {
|
||||
dimension "project"
|
||||
buildConfigField 'boolean', 'secure', "true"
|
||||
buildConfigField 'String', 'URLs', "\"${readFileToJson("dali").replace("\"", "\\\"")}\""
|
||||
buildConfigField 'String', 'mediaUrlConfig', "\"${readMediaUrlConfigFromJsonFile("dali").replace("\"", "\\\"")}\""
|
||||
buildConfigField 'String', 'musicUrlConfig', "\"${readMusicUrlConfigFromJsonFile("dali").replace("\"", "\\\"")}\""
|
||||
}
|
||||
saas {
|
||||
dimension "project"
|
||||
buildConfigField 'boolean', 'secure', "true"
|
||||
buildConfigField 'String', 'URLs', "\"${readFileToJson("saas").replace("\"", "\\\"")}\""
|
||||
buildConfigField 'String', 'mediaUrlConfig', "\"${readMediaUrlConfigFromJsonFile("saas").replace("\"", "\\\"")}\""
|
||||
buildConfigField 'String', 'musicUrlConfig', "\"${readMusicUrlConfigFromJsonFile("saas").replace("\"", "\\\"")}\""
|
||||
}
|
||||
|
||||
// 配置网络环境,QA、线上、演示
|
||||
qa {
|
||||
dimension "env"
|
||||
buildConfigField 'int', 'NET_ENV', '2'
|
||||
}
|
||||
online {
|
||||
dimension "env"
|
||||
buildConfigField 'int', 'NET_ENV', '3'
|
||||
}
|
||||
demo {
|
||||
dimension "env"
|
||||
buildConfigField 'int', 'NET_ENV', '4'
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user