- 定义变量
def a = false
- 定义字典
def appArray = [:]
appArray.merger = "merger"
- 定义数组
def defaultDB = []
defaultDB = ["Zhuanshuo"]
//遍历
defaultDB.each {
t ->
}
- 打印
println "当前APP配置:$ext.config_versions"
- 遍历数组拷贝文件+重命名
//拷贝默认logo mipmap-mdpi mipmap-hdpi mipmap-xxhdpi mipmap-xxxhdpi 四个文件夹都要拷贝
def sourceDir = "./config/copy/logo/"
def sourcePaths = ["mipmap-mdpi/", "mipmap-hdpi/", "mipmap-xxhdpi/", "mipmap-xxxhdpi/"]
def destDir = "./lib_common/src/main/res/"
sourcePaths.each {
p ->
copy() {
CopySpec copySpec ->
def logoFile1 = file(sourceDir + p + appLogo + ".png")
def dest1 = file(destDir + p)
from logoFile1
into dest1
rename {
String srcFileName ->
"icon_launcher.png"
}
}
}
- 拷贝文件夹
copy() {
CopySpec copySpec ->
println "执行Guide拷贝操作"
def dest = file("./app/src/main/assets/guide")
delete dest
from file("./config/copy/guide/$app")
into dest
}
- 拷贝+修改文件内容
//拷贝微信支付回调activity包
copy() {
CopySpec copySpec ->
def dir = appId.replace('.','/')
def dest = file("./app/src/main/java/$dir/wxapi")
println "执行WXPAY拷贝操作-->$dest"
// delete dest
// delete fileTree("./app/src/main/java"){
// include "**/WXEntryActivity.kt"
// include "**/WXPayEntryActivity.java"
// }
def sourcePath = "./config/copy/wxapi"
def file1 = file(sourcePath+"/WXEntryActivity.kt")
def file2 = file(sourcePath+"/WXPayEntryActivity.java")
// 读取到list
def list1 = file1.collect { it }
def list2 = file2.collect { it }
list1.remove(0)
list2.remove(0)
file1.write("package ${appId}.wxapi")
list1.each {t->
file1.append("\n")
file1.append(t)
}
file2.write("package ${appId}.wxapi;")
list2.each {t->
file2.append("\n")
file2.append(t)
}
from file(sourcePath)
into dest
}
网友评论