Android Studio编译输出apk文件修改文件名
新建一个Android工程,默认编译会生成一个叫app-debug.apk或者叫app-release.apk文件
通过修改build.gradle,进而修改apk文件名
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
defaultConfig {
applicationId "com.andriod.demo"
minSdkVersion 15
targetSdkVersion 21
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
if (outputFile != null && outputFile.name.endsWith('.apk')) {
//这里修改apk文件名
//def fileName = "demo_${variant.productFlavors[0].name}-${defaultConfig.versionCode}-${defaultConfig.versionName}-${releaseTime() }.apk"
def fileName = "apk名称.apk"
output.outputFile = new File(outputFile.parent, fileName)
}
}
}
APK在Project的app->build->outputs->apk里面