标题: 修改Android Studio编译输出的apk文件名 https://scz.617.cn/android/201608231610.txt AS默认编译会生成app-*.apk,位于: \app\build\outputs\apk\ 你可能想得到anything.apk,直接在文件系统中改,当然是可以的,也能通过配置达 成目的。 或许你见过这种方案 修改: \app\build.gradle -------------------------------------------------------------------------- def currenttime () { return( new Date().format( "yyyyMMdd", TimeZone.getTimeZone( "UTC" ) ) ) } android { ... android.applicationVariants.all { variant -> variant.outputs.each { output -> def oldFile, newFile if ( variant.buildType.zipAlignEnabled ) { oldFile = output.outputFile; newFile = oldFile.name.replace( "app", "${defaultConfig.applicationId}_${currenttime()}" ) output.outputFile = new File( oldFile.parent, newFile ) } oldFile = output.packageApplication.outputFile; newFile = oldFile.name.replace( "app", "${defaultConfig.applicationId}_${currenttime()}" ) output.packageApplication.outputFile = new File( oldFile.parent, newFile ) } } } -------------------------------------------------------------------------- 上面这个方案实在太不优雅,不知为何,流传甚广。 看一下优雅的方案: -------------------------------------------------------------------------- android { ... project.archivesBaseName = "${defaultConfig.applicationId}_${currenttime()}"; } -------------------------------------------------------------------------- android { ... defaultConfig { ... archivesBaseName = "${defaultConfig.applicationId}_${currenttime()}" } ... } -------------------------------------------------------------------------- 还可以修改: settings.gradle -------------------------------------------------------------------------- include ':app' def currenttime () { return( new Date().format( "yyyyMMdd", TimeZone.getTimeZone( "UTC" ) ) ) } rootProject.children.each { if ( 'app' == it.name ) { it.name = "anything_${currenttime()}" } } --------------------------------------------------------------------------