修改根目录下的settings.gradle,增加以下代码

gradle.beforeProject {    //定义变量    def pattern    def matcher    def result    //获取Config.java中的变量值    //从public static final String ServAddr = "https://10.0.0.111:9093";中抽取111    def cfgFile = file("app/src/main/java/com/jeff/demo/config/Config.java")    pattern = Pattern.compile("(?:^|\\n)[^/].*?.(\\d+):")    matcher = pattern.matcher(cfgFile.getText())    matcher.find()    def flag = matcher.group(1)    //修改build.gradle中的short_ip值    def buildFile = file("app/build.gradle")    result = buildFile.getText()    pattern = Pattern.compile("short_ip\\s.*'(\\d*)'")    matcher = pattern.matcher(result)    matcher.find()    result = matcher.replaceAll("short_ip = \'" + flag + "\'")    //修改版本号    pattern = Pattern.compile("versionCode\\s+(\\d+)")    matcher = pattern.matcher(result)    matcher.find()    def versionCode = Integer.parseInt(matcher.group(1))    result = matcher.replaceAll("versionCode " + ++versionCode)    //修改版本名    pattern = Pattern.compile("versionName\\s+\"(.+)\"")    matcher = pattern.matcher(result)    matcher.find()    int no = 0    int decade = 0    int hundred = 0    int thousand = 0    int remain = versionCode    int base = 10    int operand = base**3    if (versionCode >= operand) {        thousand = remain / operand        remain = remain % operand    }    operand = base**2    if (remain >= operand) {        hundred = remain / operand        remain = remain % operand    }    operand = base**1    if (remain >= operand) {        decade = remain / operand        remain = remain % operand    }    if (remain > 0) {        no = remain % operand    }    def versionName = "\"" + thousand + "." + hundred + "." + decade + "." + no + "\""    result = matcher.replaceAll("versionName " + versionName)    //重写文件    buildFile.write(result)}

更多相关文章

  1. Android(安卓)WebView不调用默认的 Browser
  2. 【Android】PA4D_CH7 文件、保存状态和首选项
  3. 【已解决】Android(安卓)Studio 加载自定义properties文件出错ja
  4. Android中四种实现点击事件的方法
  5. Android(安卓)TextView跑马灯效果
  6. androidsetClickable不起作用没…
  7. Android(安卓)apk安装的几种方法
  8. apple android windows app meta tags
  9. Android(安卓)Studio里c++保存opencv mat的图片

随机推荐

  1. EditText禁止输入中文设置
  2. android listview 自定义分割线总结
  3. Android开发效率—Eclipse快捷键
  4. android 应用 体会
  5. Android的Matrix图像变化原理
  6. Android Studio试用说明
  7. 新的Android恶意软件出现!可能窃取你的银
  8. android RxJava(RxAndroid)的简单使用
  9. Spring Tool Suits 配置android 开发环境
  10. 【Android 界面效果42】如何自定义字体