博客
关于我
android studio3.0build.gradle包含的svn信息apk名称写法等
阅读量:402 次
发布时间:2019-03-05

本文共 2385 字,大约阅读时间需要 7 分钟。

import java.text.SimpleDateFormatimport java.util.regex.Matcherimport java.util.regex.Patternapply plugin: 'com.android.application'android {    compileSdkVersion 26    defaultConfig {        applicationId "com.excellence.netlink"        minSdkVersion 17        targetSdkVersion 26        versionCode = getSvnVersion()        versionName = "V2.0." + versionCode + ' [' + getDate()+ "]"        println 'versionCode: '+versionCode + '\n' + 'versionName: '+versionName        creatVersionInfo()    }    buildTypes {        release {            minifyEnabled false            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'        }    }    applicationVariants.all{ variant->        variant.getPackageApplication().outputDirectory = new File(outputDir())        variant.outputs.all { output->            if (variant.buildType.name.equals('release') || variant.buildType.name.equals('debug')) {                outputFileName= "m3u8Player"+versionName+".apk"            }        }    }}def outputDir(){    return project.buildDir.absolutePath+"/outputs/apk"}def getSvnVersion() {    def proc = ("svnversion -c " + getBuildDir().parent).execute();    proc.waitFor();    def version = proc.in.text;    Pattern p = Pattern.compile("(\\d+\\:)?(\\d+)\\D?");    Matcher m = p.matcher(version);    if (m.find()) {        version = m.group(m.groupCount());    }    try    {        return Integer.parseInt(version);    }    catch (e)    {        println e.getMessage()    }    return 0;}def getDate() {    SimpleDateFormat sdf = new SimpleDateFormat('MMM d yyyy', Locale.US);    return sdf.format(new Date());}def creatVersionInfo() {    try    {        FileOutputStream outStream = new FileOutputStream(getBuildDir().parent + '/assets/verson_config.properties');        Properties properties = new Properties();        properties.put("svn_ver", '' + getSvnVersion());        properties.put("build_time", getDate());        properties.store(outStream, null);        outStream.flush();        outStream.close();    }    catch (e)    {        println e.getMessage()    }}dependencies {    implementation fileTree(dir: 'libs', include: ['*.jar'])    implementation 'com.jakewharton:butterknife:8.7.0'    annotationProcessor 'com.jakewharton:butterknife-compiler:8.7.0'    implementation 'com.vise.xiaoyaoyou:viselog:1.1.2'    implementation 'com.orhanobut:hawk:2.0.1'}

转载地址:http://vbbzz.baihongyu.com/

你可能感兴趣的文章
MSSQL日期格式转换函数(使用CONVERT)
查看>>
MSTP多生成树协议(第二课)
查看>>
MSTP是什么?有哪些专有名词?
查看>>
Mstsc 远程桌面链接 And 网络映射
查看>>
Myeclipse常用快捷键
查看>>
MyEclipse更改项目名web发布名字不改问题
查看>>
MyEclipse用(JDBC)连接SQL出现的问题~
查看>>
mt-datetime-picker type="date" 时间格式 bug
查看>>
myeclipse的新建severlet不见解决方法
查看>>
MyEclipse设置当前行背景颜色、选中单词前景色、背景色
查看>>
Mtab书签导航程序 LinkStore/getIcon SQL注入漏洞复现
查看>>
myeclipse配置springmvc教程
查看>>
MyEclipse配置SVN
查看>>
MTCNN 人脸检测
查看>>
MyEcplise中SpringBoot怎样定制启动banner?
查看>>
MyPython
查看>>
MTD技术介绍
查看>>
MySQL
查看>>
MySQL
查看>>
mysql
查看>>