一.在项目的build.gradle以下配置

安卓打包APK和SVN版本号关联

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中配置

安卓打包APK和SVN版本号关联

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中

安卓打包APK和SVN版本号关联

versionName appcodename + "_" + getVersionCode()

2.2APK打包时添加版本号

安卓打包APK和SVN版本号关联

//重命名打包文件
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"
 

 

 

 

 

 

 

 

 

 

 

相关文章:

  • 2021-11-29
  • 2022-12-23
  • 2021-04-15
  • 2021-11-11
  • 2021-02-20
  • 2022-02-08
猜你喜欢
  • 2022-02-08
  • 2021-07-06
  • 2021-09-15
  • 2021-05-23
  • 2021-04-29
  • 2022-01-06
  • 2021-04-05
相关资源
相似解决方案