[m1]
[1.0.0] [添加url+flavors过滤单独抽出文件]
This commit is contained in:
144
app/build.gradle
144
app/build.gradle
@@ -254,17 +254,14 @@ android {
|
||||
qa {
|
||||
dimension "env"
|
||||
buildConfigField 'int', 'NET_ENV', '2'
|
||||
buildConfigField 'String', 'URLs', "\"${readFileToJson("qa").replace("\"","\\\"")}\""
|
||||
}
|
||||
online {
|
||||
dimension "env"
|
||||
buildConfigField 'int', 'NET_ENV', '3'
|
||||
buildConfigField 'String', 'URLs', "\"${readFileToJson("online").replace("\"","\\\"")}\""
|
||||
}
|
||||
demo {
|
||||
dimension "env"
|
||||
buildConfigField 'int', 'NET_ENV', '4'
|
||||
buildConfigField 'String', 'URLs', "\"${readFileToJson("demo").replace("\"","\\\"")}\""
|
||||
}
|
||||
}
|
||||
|
||||
@@ -281,105 +278,8 @@ android {
|
||||
apply from: "./productFlavors/fOchSweeper.gradle"
|
||||
apply from: "./productFlavors/fMultiDisplayOchBus.gradle"
|
||||
apply from: "./productFlavors/fMultiDisplayOchTaxi.gradle"
|
||||
|
||||
variantFilter { variant ->
|
||||
def names = variant.flavors*.name
|
||||
//要检查特定的构建类型,请使用variant.buildType.name ==“ <buildType>”
|
||||
if(names.contains("mogo")) {
|
||||
// region 过滤noop 的flavors 不带och业务的
|
||||
if (names.contains("noop")&&!names.contains("fPadLenovo")) {
|
||||
//Gradle会忽略满足上述条件的所有变体
|
||||
setIgnore(true)
|
||||
}
|
||||
// endregion
|
||||
// region 过滤sweper 的flavors
|
||||
if (names.contains("sweeper") && !names.contains("fOchSweeper")) {
|
||||
//Gradle会忽略满足上述条件的所有变体
|
||||
setIgnore(true)
|
||||
}
|
||||
// endregion
|
||||
// region 过滤shuttle 的flavors
|
||||
if (names.contains("shuttle")) {
|
||||
//Gradle会忽略满足上述条件的所有变体
|
||||
if (names.contains("fOchBus")) {
|
||||
} else if (names.contains("fOchBusPassenger")) {
|
||||
} else {
|
||||
setIgnore(true)
|
||||
}
|
||||
}
|
||||
// endregion
|
||||
// region 过滤taxi 的flavors
|
||||
if (names.contains("taxi")) {
|
||||
//Gradle会忽略满足上述条件的所有变体
|
||||
if (names.contains("fOchTaxi")) {
|
||||
} else if (names.contains("fOchTaxiPassenger")) {
|
||||
} else if (names.contains("fPadLenovo")) {
|
||||
} else if (names.contains("fMultiDisplayOchTaxi")) {
|
||||
} else {
|
||||
setIgnore(true)
|
||||
}
|
||||
}
|
||||
// endregion
|
||||
// region 过滤bus 的flavors
|
||||
if (names.contains("bus")) {
|
||||
//Gradle会忽略满足上述条件的所有变体
|
||||
if (names.contains("fOchBus")) {
|
||||
} else if (names.contains("fOchBusPassenger")) {
|
||||
} else if (names.contains("fMultiDisplayOchBus")) {
|
||||
} else if (names.contains("fOchBusPassengerM1")) {
|
||||
} else if (names.contains("fOchBusPassengerM2")) {
|
||||
} else {
|
||||
setIgnore(true)
|
||||
}
|
||||
}
|
||||
// endregion
|
||||
}
|
||||
else if(names.contains("dali")){
|
||||
// region 过滤noop 的flavors 不带och业务的
|
||||
if (names.contains("noop")) {
|
||||
//Gradle会忽略满足上述条件的所有变体
|
||||
setIgnore(true)
|
||||
}
|
||||
// endregion
|
||||
// region 过滤sweper 的flavors
|
||||
if (names.contains("sweeper")) {
|
||||
//Gradle会忽略满足上述条件的所有变体
|
||||
setIgnore(true)
|
||||
}
|
||||
// endregion
|
||||
// region 过滤taxi 的flavors
|
||||
if (names.contains("taxi")) {
|
||||
setIgnore(true)
|
||||
}
|
||||
// endregion
|
||||
// region 过滤shuttle 的flavors
|
||||
if (names.contains("shuttle")) {
|
||||
//Gradle会忽略满足上述条件的所有变体
|
||||
if (names.contains("fOchShuttle")) {
|
||||
} else if (names.contains("fOchShuttlePassenger")) {
|
||||
} else {
|
||||
setIgnore(true)
|
||||
}
|
||||
}
|
||||
// endregion
|
||||
// region 过滤bus 的flavors
|
||||
if (names.contains("bus")) {
|
||||
//Gradle会忽略满足上述条件的所有变体
|
||||
if (names.contains("fOchBus")) {
|
||||
} else if (names.contains("fOchBusPassenger")) {
|
||||
} else if (names.contains("fMultiDisplayOchBus")) {
|
||||
} else if (names.contains("fOchBusPassengerM1")) {
|
||||
} else if (names.contains("fOchBusPassengerM2")) {
|
||||
} else {
|
||||
setIgnore(true)
|
||||
}
|
||||
}
|
||||
// endregion
|
||||
}
|
||||
else {
|
||||
setIgnore(true)
|
||||
}
|
||||
}
|
||||
apply from: "./productFlavors/urlConfig.gradle"
|
||||
apply from: "./productFlavors/flavorsFilterConfig.gradle"
|
||||
|
||||
packagingOptions {
|
||||
exclude 'META-INF/io.netty.versions.properties'
|
||||
@@ -566,43 +466,3 @@ boolean isReleaseBuild() {
|
||||
return false
|
||||
}
|
||||
|
||||
Object readFileToJson(env){
|
||||
try {
|
||||
def businessType = project.hasProperty('business')
|
||||
if(businessType){
|
||||
println("businessType:${businessType}----${business}")
|
||||
}
|
||||
// 加载config.json 文件
|
||||
File file = new File("${rootDir}/app/config.json")
|
||||
def jsonSlurper = new JsonSlurper()
|
||||
// 解析json
|
||||
def config = jsonSlurper.parse(file)
|
||||
def flavorNames = variantName()
|
||||
def jsonOutput = new JsonOutput()
|
||||
config.each {key, value ->
|
||||
// 匹配flavor对应的 json
|
||||
if(flavorNames.toLowerCase().contains(key)){
|
||||
return jsonOutput.toJson(value.get(env))
|
||||
}
|
||||
}
|
||||
// 保底原则
|
||||
return jsonOutput.toJson(config.get("bus").get(env))
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
def variantName() {
|
||||
def taskName = getGradle().getStartParameter().getTaskRequests().toString()
|
||||
def split = taskName.split(":")
|
||||
if (split.length > 2){
|
||||
return split[2].toString().split("]")[0].replace("assemble","")
|
||||
}else {
|
||||
if(taskName.contains("bus")) {
|
||||
return "bus"
|
||||
}else {
|
||||
return "taxi"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,46 +1,24 @@
|
||||
{
|
||||
"bus": {
|
||||
"mogo": {
|
||||
"qa": {
|
||||
"och_url":"https://tech-qa.zhidaohulian.com"
|
||||
"och_url": "https://tech-qa.zhidaohulian.com"
|
||||
},
|
||||
"online": {
|
||||
"och_url":"https://tech.zhidaohulian.com"
|
||||
"och_url": "https://tech-qa.zhidaohulian.com"
|
||||
},
|
||||
"demo": {
|
||||
"och_url":"http://tech-dev.zhidaohulian.com"
|
||||
"och_url": "https://tech-qa.zhidaohulian.com"
|
||||
}
|
||||
},
|
||||
"taxi": {
|
||||
"dali": {
|
||||
"qa": {
|
||||
"och_url":"https://tech-qa.zhidaohulian.com"
|
||||
"och_url": "https://tech-qa.zhidaohulian.com"
|
||||
},
|
||||
"online": {
|
||||
"och_url":"https://tech.zhidaohulian.com"
|
||||
"och_url": "https://tech-qa.zhidaohulian.com"
|
||||
},
|
||||
"demo": {
|
||||
"och_url":"http://tech-dev.zhidaohulian.com"
|
||||
}
|
||||
},
|
||||
"shuttle": {
|
||||
"qa": {
|
||||
"och_url":"https://och-driver-qa.zhidaozhixing.com"
|
||||
},
|
||||
"online": {
|
||||
"och_url":"https://och-driver.zhidaozhixing.com"
|
||||
},
|
||||
"demo": {
|
||||
"och_url":"http://och-driver-dev.zhidaozhixing.com"
|
||||
}
|
||||
},
|
||||
"sweeper": {
|
||||
"qa": {
|
||||
"och_url":"https://och-driver-qa.zhidaozhixing.com"
|
||||
},
|
||||
"online": {
|
||||
"och_url":"https://och-driver.zhidaozhixing.com"
|
||||
},
|
||||
"demo": {
|
||||
"och_url":"http://och-driver-dev.zhidaozhixing.com"
|
||||
"och_url": "https://tech-qa.zhidaohulian.com"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
102
app/productFlavors/flavorsFilterConfig.gradle
Normal file
102
app/productFlavors/flavorsFilterConfig.gradle
Normal file
@@ -0,0 +1,102 @@
|
||||
|
||||
project.android.variantFilter { variant ->
|
||||
def names = variant.flavors*.name
|
||||
//要检查特定的构建类型,请使用variant.buildType.name ==“ <buildType>”
|
||||
if(names.contains("mogo")) {
|
||||
// region 过滤noop 的flavors 不带och业务的
|
||||
if (names.contains("noop")&&!names.contains("fPadLenovo")) {
|
||||
//Gradle会忽略满足上述条件的所有变体
|
||||
setIgnore(true)
|
||||
}
|
||||
// endregion
|
||||
// region 过滤sweper 的flavors
|
||||
if (names.contains("sweeper") && !names.contains("fOchSweeper")) {
|
||||
//Gradle会忽略满足上述条件的所有变体
|
||||
setIgnore(true)
|
||||
}
|
||||
// endregion
|
||||
// region 过滤shuttle 的flavors
|
||||
if (names.contains("shuttle")) {
|
||||
//Gradle会忽略满足上述条件的所有变体
|
||||
if (names.contains("fOchBus")) {
|
||||
} else if (names.contains("fOchBusPassenger")) {
|
||||
} else {
|
||||
setIgnore(true)
|
||||
}
|
||||
}
|
||||
// endregion
|
||||
// region 过滤taxi 的flavors
|
||||
if (names.contains("taxi")) {
|
||||
//Gradle会忽略满足上述条件的所有变体
|
||||
if (names.contains("fOchTaxi")) {
|
||||
} else if (names.contains("fOchTaxiPassenger")) {
|
||||
} else if (names.contains("fPadLenovo")) {
|
||||
} else if (names.contains("fMultiDisplayOchTaxi")) {
|
||||
} else {
|
||||
setIgnore(true)
|
||||
}
|
||||
}
|
||||
// endregion
|
||||
// region 过滤bus 的flavors
|
||||
if (names.contains("bus")) {
|
||||
//Gradle会忽略满足上述条件的所有变体
|
||||
if (names.contains("fOchBus")) {
|
||||
} else if (names.contains("fOchBusPassenger")) {
|
||||
} else if (names.contains("fMultiDisplayOchBus")) {
|
||||
} else if (names.contains("fOchBusPassengerM1")) {
|
||||
} else if (names.contains("fOchBusPassengerM2")) {
|
||||
} else {
|
||||
setIgnore(true)
|
||||
}
|
||||
}
|
||||
// endregion
|
||||
}
|
||||
else if(names.contains("dali")){
|
||||
// region 过滤noop 的flavors 不带och业务的
|
||||
if (names.contains("noop")) {
|
||||
//Gradle会忽略满足上述条件的所有变体
|
||||
setIgnore(true)
|
||||
}
|
||||
// endregion
|
||||
// region 过滤sweper 的flavors
|
||||
if (names.contains("sweeper")) {
|
||||
//Gradle会忽略满足上述条件的所有变体
|
||||
setIgnore(true)
|
||||
}
|
||||
// endregion
|
||||
// region 过滤taxi 的flavors
|
||||
if (names.contains("taxi")) {
|
||||
setIgnore(true)
|
||||
}
|
||||
// endregion
|
||||
// region 过滤shuttle 的flavors
|
||||
if (names.contains("shuttle")) {
|
||||
//Gradle会忽略满足上述条件的所有变体
|
||||
if (names.contains("fOchShuttle")) {
|
||||
} else if (names.contains("fOchShuttlePassenger")) {
|
||||
} else {
|
||||
setIgnore(true)
|
||||
}
|
||||
}
|
||||
// endregion
|
||||
// region 过滤bus 的flavors
|
||||
if (names.contains("bus")) {
|
||||
//Gradle会忽略满足上述条件的所有变体
|
||||
if (names.contains("fOchBus")) {
|
||||
} else if (names.contains("fOchBusPassenger")) {
|
||||
} else if (names.contains("fMultiDisplayOchBus")) {
|
||||
} else if (names.contains("fOchBusPassengerM1")) {
|
||||
} else if (names.contains("fOchBusPassengerM2")) {
|
||||
} else {
|
||||
setIgnore(true)
|
||||
}
|
||||
}
|
||||
// endregion
|
||||
}
|
||||
else {
|
||||
setIgnore(true)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
49
app/productFlavors/urlConfig.gradle
Normal file
49
app/productFlavors/urlConfig.gradle
Normal file
@@ -0,0 +1,49 @@
|
||||
import groovy.json.JsonOutput
|
||||
import groovy.json.JsonSlurper
|
||||
|
||||
project.android.applicationVariants.all { variant ->
|
||||
def flavorName = variant.flavorName
|
||||
if (flavorName.startsWith("dali")) {//大理环境
|
||||
if (flavorName.endsWith("Qa")) {
|
||||
buildConfigField 'String', 'URLs', "\"${readFileToJson("dali", "qa").replace("\"", "\\\"")}\""
|
||||
} else if (flavorName.endsWith("Online")) {
|
||||
buildConfigField 'String', 'URLs', "\"${readFileToJson("dali", "online").replace("\"", "\\\"")}\""
|
||||
} else if (flavorName.endsWith("Demo")) {
|
||||
buildConfigField 'String', 'URLs', "\"${readFileToJson("dali", "demo").replace("\"", "\\\"")}\""
|
||||
}
|
||||
} else { // mogo环境
|
||||
if (flavorName.endsWith("Qa")) {
|
||||
buildConfigField 'String', 'URLs', "\"${readFileToJson("mogo", "qa").replace("\"", "\\\"")}\""
|
||||
} else if (flavorName.endsWith("Online")) {
|
||||
buildConfigField 'String', 'URLs', "\"${readFileToJson("mogo", "online").replace("\"", "\\\"")}\""
|
||||
} else if (flavorName.endsWith("Demo")) {
|
||||
buildConfigField 'String', 'URLs', "\"${readFileToJson("mogo", "demo").replace("\"", "\\\"")}\""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Object readFileToJson(project, env) {
|
||||
try {
|
||||
// 加载config.json 文件
|
||||
File file = new File("${rootDir}/app/config.json")
|
||||
def jsonSlurper = new JsonSlurper()
|
||||
// 解析json
|
||||
def config = jsonSlurper.parse(file)
|
||||
def jsonOutput = new JsonOutput()
|
||||
config.each { key, value ->
|
||||
// 匹配flavor对应的 json
|
||||
if (project.toLowerCase().contains(key)) {
|
||||
return jsonOutput.toJson(value.get(env))
|
||||
}
|
||||
}
|
||||
// 保底原则
|
||||
return jsonOutput.toJson(config.get("mogo").get(env))
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ dependencies {
|
||||
implementation rootProject.ext.dependencies.androidxappcompat
|
||||
|
||||
implementation rootProject.ext.dependencies.arouter
|
||||
implementation "com.android.tools.build:gradle:3.5.3"
|
||||
kapt rootProject.ext.dependencies.aroutercompiler
|
||||
|
||||
if (Boolean.valueOf(USE_MAVEN_PACKAGE)) {
|
||||
|
||||
Reference in New Issue
Block a user