上一篇文章:
一.jenkins+github+gradle 实现android自动化打包全攻略(MAC版)
http://www.jianshu.com/p/9caab25d2cf1
上次已经实现自动打包,那么如何进行APK自定义包名呢?如何进行自签名呢?
主要通过设置项目的build.gradle

一.自定义APK的名称
比如格式为:时间项目名称版本号.apk

applicationVariants.all { variant ->if (variant.buildType.name.equals('release')) {variant.outputs.each { output -> def outputFile = output.outputFileif (outputFile != null && outputFile.name.endsWith('.apk')) {def fileName = "${releaseTime()}_com.andli.myproject_${defaultConfig.versionName}.apk"output.outputFile = new File(outputFile.parent, fileName)}}}}
def releaseTime() {return new Date().format("yyyyMMdd", TimeZone.getTimeZone("UTC"))}
还可以自定义APK的输出路径:比如导出到下载目录
output.outputFile = new File(“/Users/XXX/Downloads”, fileName)
二.自定义签名

signingConfigs {//签名的配置release {storeFile file("签名文件名称.jks")storePassword '密码'keyAlias '签名文件别名'keyPassword '密码'}}
signingConfig signingConfigs.release//打包命令行:gradlew assembleRelease
lintOptions {//设置编译的lint开关,程序在buid的时候,会执行lint检查,有任何的错误或者警告提示,都会终止构建abortOnError false}
打包后的效果:

待解决的问题
APK名称带时分秒,但是时与北京时间相差8小时
解决办法:获取重庆时间
new Date().format("yyyyMMdd HH:mm:ss", TimeZone.getTimeZone("Asia/Chongqing"))

参考文章:
http://www.jianshu.com/p/83a99e26826c

