美文网首页
Gradle的使用

Gradle的使用

作者: izheer | 来源:发表于2022-06-13 09:26 被阅读0次

1、打包时获取SVN号设置APK文件名;

// 在工程下的build.gradle 文件添加
classpath "org.tmatesoft.svnkit:svnkit:1.8.11" //获取SVN号

// 在App的build.gradle文件
plugins{
    id 'com.android.application'
}
import org.tmatesoft.svn.core.wc.*//获取SVN号

//获取SVN号
def getSvnRevision() {
    ISVNOptions options = SVNWCUtil.createDefaultOptions(true)
    SVNClientManager clientManager = SVNClientManager.newInstance(options)
    SVNStatusClient statusClient = clientManager.getStatusClient()
    SVNStatus status = statusClient.doStatus(rootDir.getParentFile().getParentFile(), false)
    SVNRevision revision = status.getCommittedRevision()
    return revision.getNumber()
}
def getDateTime(){
    return  new Date().format("yyMMddHH", TimeZone.getTimeZone("UTC"))
}
android{
      
      applicationVariants.all{
        variant ->
            variant.outputs.all {
                //在这里修改apk文件名
                outputFileName = "name_${defaultConfig.versionName}-${getSvnRevision()}-${variant.name}-${getDateTime()}.apk"
            }
    }
}

相关文章

网友评论

      本文标题:Gradle的使用

      本文链接:https://www.haomeiwen.com/subject/cpzamrtx.html