android studio 3.0 修改release生成的apk名称

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.example.builder.myapplication"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {

        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    //自动生成指定名称的release发布版的 apk文件
    android.applicationVariants.all { variant ->
        def appName
        if (project.hasProperty("applicationName")) {
            appName = applicationName
        } else {
            appName = parent.name
        }
        variant.outputs.all { output ->
            outputFileName = "Builder_${buildTime()}.apk"
        }
    }
}

def buildTime() {
    def date = new Date()
    def formattedDate = date.format('yyyyMMdd')
    return formattedDate
}

你可能感兴趣的:(安卓基础知识点)