博客
关于我
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/

你可能感兴趣的文章
Mysql 事务知识点与优化建议
查看>>
Mysql 优化 or
查看>>
mysql 优化器 key_mysql – 选择*和查询优化器
查看>>
MySQL 优化:Explain 执行计划详解
查看>>
Mysql 会导致锁表的语法
查看>>
mysql 使用sql文件恢复数据库
查看>>
mysql 修改默认字符集为utf8
查看>>
Mysql 共享锁
查看>>
MySQL 内核深度优化
查看>>
mysql 内连接、自然连接、外连接的区别
查看>>
mysql 写入慢优化
查看>>
mysql 分组统计SQL语句
查看>>
Mysql 分页
查看>>
Mysql 分页语句 Limit原理
查看>>
MySql 创建函数 Error Code : 1418
查看>>
MySQL 创建新用户及授予权限的完整流程
查看>>
mysql 创建表,不能包含关键字values 以及 表id自增问题
查看>>
mysql 删除日志文件详解
查看>>
mysql 判断表字段是否存在,然后修改
查看>>
MySQL 到底能不能放到 Docker 里跑?
查看>>