一.在项目的build.gradle以下配置
classpath group: 'org.tmatesoft.svnkit', name: 'svnkit', version: '1.8.11'//添加svn版本的插件
gradle.projectsEvaluated { tasks.withType(JavaCompile) { //此处是相对路径,服务器和本地统一使用这个路径 options.compilerArgs.add('-Xbootclasspath/p:app/tvos/framework.jar') } }
二.moudle的bulid.gradle中配置
import org.tmatesoft.svn.core.wc.*
//获取SVN版本的方法 def getSvnRevision() { ISVNOptions options = SVNWCUtil.createDefaultOptions(true); SVNClientManager clientManager = SVNClientManager.newInstance(options); SVNStatusClient statusClient = clientManager.getStatusClient(); SVNStatus status = statusClient.doStatus(projectDir, false); SVNRevision revision = status.getCommittedRevision(); return revision.getNumber(); } def getVersionCode = { long svnVersion = getSvnRevision() return svnVersion.toInteger() } def appcodename = rootProject.ext.versionName //版本号名 //打包时间 def releaseTime() { return new Date().format("yyyyMMdd", TimeZone.getTimeZone("UTC")) }
2.1将svn版本号添加到versionName中
versionName appcodename + "_" + getVersionCode()
2.2APK打包时添加版本号
//重命名打包文件 android.applicationVariants.all { variant -> variant.outputs.all { //以下方式,apk文件名为:版本号信息_20190619.apk outputFileName = variant.versionName + "_" + releaseTime() + ".apk" } }
2.2.1扩展
buildType.name打包类型:比如release或者debug
//以下方式,apk文件名为:XXX_v2.2.0_release_2019-06-19.apk
outputFileName = "XXX_v${variant.versionName}_${buildType.name}_${currentTime()}.apk"