不多说直接上代码(build.gradle 代码):关键地方都有注释
buildscript {
repositories {
jcenter();
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
}
}
println("I'm now compiling with gradle " + project.gradle.gradleVersion);
apply plugin: 'com.android.application'
dependencies {
compile fileTree(include: '*.jar', dir: 'libs')
compile 'com.android.support:multidex:1.0.1'
}
//获取当前时间
def releaseTime() {
return new Date().format("yyyy-MM-dd HH.mm.ss", TimeZone.getTimeZone("GMT+08:00"))
}
//读取文件中的字符串并替换
def fileReader(path, oldStr, newStr) {
def readerString = "";
new File(path).withReader('UTF-8') { reader ->
reader.eachLine {
if (it.find(oldStr)) {
it = it.replace(oldStr, newStr)
}
readerString <<= it
readerString << '\n'
}
return readerString
}
}
//写文件
def fileWrite(path, stringBuffer) {
new File(path).withWriter('UTF-8') {
within ->
within.append(stringBuffer)
}
}
android {
compileSdkVersion 22
buildToolsVersion '23.0.2'
defaultConfig {