一.在項目的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"