Android Studio生成APK自动追加版本号、自定义apk名称、指定签名证书文件

你也可以查看我的其他同类文章,也会让你有一定的收货!

生成APK自动追加版本号

可自动区分debug和release,并追加版本号:

  1. 打开 build.gradle

  2. 在 android 节点中插入下面代码

第一种:

   applicationVariants.all{ variant->
        variant.outputs.each { output-> def oldFile = output.outputFile def newName = ''; if(variant.buildType.name.equals('release')){ // println(variant.productFlavors[0].name) // def releaseApkName = 'study-' + defaultConfig.versionName + '-luckpan.apk' def releaseApkName = defaultConfig.applicationId + "-" + buildType.name + "-" + defaultConfig.versionName + '.apk' output.outputFile = new File(oldFile.parent, releaseApkName) } if(variant.buildType.name.equals('beta')){ newName = oldFile.name.replace(".apk", "-v" + getVersionNameFromManifest() + "-build" + getDate() + ".apk") output.outputFile = new File(oldFile.parent, newName) } if(variant.buildType.name.equals('debug')){ } } }

第二种:

把productFlavors名字和 buildType名字,打包到apk文件名中

android.applicationVariants.all { variant ->
    variant.outputs.each { output ->
        output.outputFile = new File(output.outputFile.parent, defaultConfig.applicationId + "-" + buildType.name + "-v" + defaultConfig.versionName "-" + variant.productFlavors.name + "-" + defaultConfig.versionCode + ".apk" ); } }

 

groovy语言执行的最后一行是返回值

  • 函数 getVersionNameFromManifest(),从manifest文件中读取的版本号

  • 版本号定义在build.gradle中,那defaultConfig.versionName就是你的版本号

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值