Android(安卓)Studio生成APK自动追加版本号
16lz
2021-12-04
参考:http://www.sollyu.com/android-apk-studio-generated-automatically-appends-a-version-number/
http://www.th7.cn/Program/Android/201501/380594.shtml?WebShieldDRSessionVerify=SVUnBrv9lvKUzUH4e6nR
http://blog.csdn.net/jt_ontheway/article/details/50482210
可自动区分debug和release,并追加版本号:
打开 build.gradle
在 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' 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')){ } } }
第二种:
android.applicationVariants.all { variant -> variant.outputs.each { output -> output.outputFile = new File(output.outputFile.parent, defaultConfig.applicationId + "-" + buildType.name + "-v" + defaultConfig.versionName + "-" + defaultConfig.versionCode + ".apk" ); }}
groovy语言执行的最后一行是返回值
函数 getVersionNameFromManifest(),从manifest文件中读取的版本号
版本号定义在build.gradle中,那defaultConfig.versionName就是你的版本号
更多相关文章
- android应用和系统版本信息
- 实习杂记(20)---Android里面shape定义图形相关属性
- android studio 中设置apk的版本号
- android自动更新新版模块(简单,实用)
- Android(安卓)版本号和分支查看
- Android(安卓)webkit image的加载过程解析(二)
- android 自动更新apk版本
- 数据存储和界面笔记
- 【Android-002】【常见布局】