android studio3.0build.gradle包含的svn信息apk名称写法等

import java.text.SimpleDateFormat
import java.util.regex.Matcher
import java.util.regex.Pattern

apply 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'
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

景兄弟1366

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值