zoukankan      html  css  js  c++  java
  • Android: android studio配置生成自定义apk名称

    1.Android Studio 3.0之前:

     在build.gradled 的 android {} 内添加如下代码:

    android.applicationVariants.all { variant ->  //如果是Library,例如aar包则使用 android.libraryVariants.all 且下面后缀判断修改为 .arr
            variant.outputs.each { output ->
     def fileName = "demo_${defaultConfig.versionCode}-${defaultConfig.versionName}-${releaseTime()}.apk" def outputFile = output.outputFile if (outputFile != null && outputFile.name.endsWith('.apk')) { //这里修改apk文件名 output.outputFile = new File(outputFile.parent, fileName)  
           
    }
        }
    }

     在 android {} 之外声明 releaseTime() 方法:

    //获取编译时间
    def releaseTime() {
        return new Date().format("yyyy-MM-dd", TimeZone.getTimeZone("UTC"))
    }

    2.Android Studio 3.0之后:

     outputFile变为只读,需把each修改为all,然后通过outputFileName修改生成apk的名称,此外AS 3.0后打包完,除了apk包文件,还会多一个 output.json 参数文件。

        新版修改如下:

        //自定义apk名称含版本号信息
        android.applicationVariants.all { variant ->
            variant.outputs.all { output ->  //旧版为:each
                def fileName = "demo_${defaultConfig.versionCode}-${defaultConfig.versionName}-${releaseTime()}.apk"
                def outputFile = output.outputFile
                if (outputFile != null && outputFile.name.endsWith('.apk')) {
                    //这里修改apk文件名
                    outputFileName = fileName  //旧版为:output.outputFile = new File(outputFile.parent, fileName)
                }
            }
        }

     同样在 android {} 之外声明 releaseTime() 方法:

    //获取编译时间
    def releaseTime() {
        return new Date().format("yyyy-MM-dd", TimeZone.getTimeZone("UTC"))
    }

    -end-

  • 相关阅读:
    arm gdbserver armlinuxgdb
    建立非模态对话框与在线程中建立非模态对话框
    AutoLock C++
    Uboot bootcmd 和bootargs
    SetRegistryKey
    飞凌OK6410 uboot支持网络
    uboot 源码修改 bootcmd,IP ,BOOTARGS等参数
    TextBox(richTextBox) 光标和滚动条到文本末尾
    Windbg中使用查找内存并设置访问断点
    opencv EXAMPLES 编译 VS2010 (C++)
  • 原文地址:https://www.cnblogs.com/blogs-of-lxl/p/9366532.html
Copyright © 2011-2022 走看看