• Android Stdio 如何自定义生成APK的名称


        Android Stdio自动默认生成的app的名称都是app-release或者app-debug,生成完后还要手动更改apk的名称,很是麻烦。

       自定义生成APK的名称的方法:在appuild.gradle这个文件里添加如下内容

    apply plugin: 'com.android.application'
    
    def getTime() {
        return new Date().format("yyyyMMdd", TimeZone.getDefault());
    }
    
    android {
        compileSdkVersion 22
        buildToolsVersion "25.0.2"
    
        defaultConfig {
            applicationId "com.example.myapplication"
            minSdkVersion 19
            targetSdkVersion 22
            versionCode 1
            versionName "1.0"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    
        // 打包后应用名称
        applicationVariants.all { variant ->
            variant.outputs.each { output ->
                def outputFile = output.outputFile
                def fileName
                if (outputFile != null && outputFile.name.endsWith('.apk')) {
                    if (variant.buildType.name.equals('release')) {
                        fileName = "LoverHeart_Release${defaultConfig.versionName}.${getTime()}.apk"
                    } else if (variant.buildType.name.equals('debug')) {
                        fileName = "LoverHeart_Debug${defaultConfig.versionName}.${getTime()}.apk"
                    }
                    output.outputFile = new File(outputFile.parent, fileName)
                }
    
            }
        }
    }
    
    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        testCompile 'junit:junit:4.12'
        compile 'com.android.support:appcompat-v7:22.2.1'
        compile 'com.android.support:design:22.2.1'
    }

    生成的apk包名为:LoverHeart_Release1.0.20170417.apk

        

    高山流水,海纳百川!
  • 相关阅读:
    local 不能解析为127.0.0.1
    完全使用接口方式调用WCF 服务
    【人生】自己对于求职应聘的一些感受
    OO的经典例子
    剪刀、石头、布机器人比赛
    TextTree 文本资料收集轻量级工具
    两个代替重复输入的小工具
    桌面助手 Desktop Helper 自动帮你关闭指定的窗口
    磁盘可用空间平衡
    用C#制造可以继承的“枚举”
  • 原文地址:https://www.cnblogs.com/ahcc08/p/6724419.html
Copyright © 2020-2023  润新知