参考: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,并追加版本号:

  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'                 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就是你的版本号

更多相关文章

  1. android应用和系统版本信息
  2. 实习杂记(20)---Android里面shape定义图形相关属性
  3. android studio 中设置apk的版本号
  4. android自动更新新版模块(简单,实用)
  5. Android(安卓)版本号和分支查看
  6. Android(安卓)webkit image的加载过程解析(二)
  7. android 自动更新apk版本
  8. 数据存储和界面笔记
  9. 【Android-002】【常见布局】

随机推荐

  1. Android学习心得之二——Android系统架构
  2. Android多线程AsyncTask详解
  3. android截屏代码实现方法
  4. 只会写xml和Activity,做android真的不行!
  5. 10个常见的 Android(安卓)新手误区
  6. Android之Android的数据存储--SD卡
  7. Android(安卓)sdk manager不能更新下载缓
  8. 【转官方】Android(安卓)ADB调试命令、支
  9. webview中的javascript调用android命令实
  10. 五年之内,Android(安卓)或将被取代?