使用SVN进行版本控制时,可以在SVN仓库目录下用控制台命令 svn info,获取当前版本库的相关信息
D:\android_work\70\VoChat>svn info
Path: .
Working Copy Root Path: D:\android_work\70
URL: https://192.168.1.6/svn/DCW-BWC-Android/trunk/70/VoChat
Relative URL: ^/trunk/70/VoChat
Repository Root: https://192.168.1.6/svn/DCW-BWC-Android
Repository UUID: 58e1edc7-d5fb-2f4c-89ac-86f58ceef04f
Revision: 378
Node Kind: directory
Schedule: normal
Last Changed Author: lixiaobin
Last Changed Rev: 378
Last Changed Date: 2020-04-27 16:57:09 +0800 (周一, 27 四月 2020)
D:\android_work\70\VoChat>
利用这一点,我们可以在APP的版本信息中,加入对应元素,比如说 Revision的值,在.gradle文件中添加对应的方法
def static getSVNVersion() {
String svninfo ="svn info".execute().text.trim()
BufferedReader br = new BufferedReader(new StringReader(svninfo))
String lineStr;
while ((lineStr = br.readLine())!=null) {
if (lineStr.contains("Revision")) {
String[] params = lineStr.split(":")
if (params.length == 2 && params[0] != null && params[1] != null) {
if (params[0].trim().equals("Revision")) {
return params[1].trim()
}
}
}
}
return "000"
}
然后添加到app的版本信息中
//defaultConfig
minSdkVersion = 17
targetSdkVersion = 28
versionCode = releaseTimeForCode(todayBuildTimes)
versionNamePrefix = "sanxing"
versionName = versionNamePrefix.concat("V0.1.6.").concat(getSVNVersion()).concat("_").concat(releaseTimeForName())
// versionName = versionNamePrefix.concat(getSVNVersion()).concat('_').concat(releaseTimeForName())
println "SVN仓库版本号为:"+getSVNVersion()
println "versionCode:"+versionCode
println "versionName:"+versionName
OK!完事,这样每次编译版本信息中就能体现出svn的Revision了
网友评论