Android studio 默认生成的apk文件名是这样的
![这里写图片描述](https://img-blog.csdn.net/20160807115740477)
当我们需要生成自定义文件名apk的时候可以在Gradle文件中定义, 避免每次生成后还要改名.
示例如下
![这里写图片描述](https://img-blog.csdn.net/20160807120438534)
build.gradle
apply plugin: 'com.android.application'
def getTime() {
return new Date().format("yyyyMMdd", TimeZone.getDefault());
}
android {
compileSdkVersion 23
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "com.maimiho.myapplication"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
applicationVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
def fileName
if (outputFile != null && outputFile.name.endsWith('.apk')) {
if (variant.buildType.name.equals('release')) {
fileName = "RELEASE${defaultConfig.versionName}.${getTime()}.apk"
} else if (variant.buildType.name.equals('debug')) {
fileName = "DEBUG${defaultConfig.versionName}.${getTime()}.apk"
}
output.outputFile = new File(outputFile.parent, fileName)
}
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
}
![这里写图片描述](https://img-blog.csdn.net/20160807120711085)