android - Android Studio 2.2重命名apk文件

标签 android gradle android-gradle-plugin android-studio-2.2

我在build.gradle中有此代码可重命名de apk,但由于Android Studio更新至2.2版不再有效。

apply plugin: 'com.android.application'

def getDate() {
    def date = new Date()
    def formattedDate = date.format('yyMMdd')
    return formattedDate
}

def gitBranch() {
    def branch = ""
    def proc = "git rev-parse --abbrev-ref HEAD".execute()
    proc.in.eachLine { line -> branch = line }
    proc.err.eachLine { line -> println line }
    proc.waitFor()
    branch
}

android {

    // defaultConfig, buildTypes, etc.

    android.applicationVariants.all { variant ->

        def versionName = variant.versionName.replaceAll('\\.', '_')
        def date = getDate()
        def versionCode = variant.versionCode
        def branch = gitBranch()

        variant.outputs.each { output ->
            def newApkName
            if (output.zipAlign) {
                newApkName = "APP${versionName}D${date}VC${versionCode}-${branch}.apk"
                output.outputFile = new File(output.outputFile.parent, newApkName)
            }
        }
    }
}

我添加了一些println来查看newApk名称是否正确,并且没有问题。各位,您知道其他替代方法吗?我将永远感激不已。

最佳答案

通过采用新的默认打包管道来处理一项任务中的压缩,签名和zipaligning,从而提高构建性能。您可以通过将android.useOldPackaging = true添加到yourgradle.properties文件来恢复使用较旧的打包工具。使用新的打包工具时,zipalignDebug任务不可用。但是,您可以通过调用createZipAlignTask(String taskName,File inputFile,File outputFile)方法来自己创建一个。

从发行说明中:
https://developer.android.com/studio/releases/gradle-plugin.html#revisions

关于android - Android Studio 2.2重命名apk文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39605852/

相关文章:

android-ndk - android - ndk 不将预构建库复制到我的 apk

android - 多项目 androidTest 依赖项

java - 使用 Android 或 Java 从 MediaWiki/Wikipedia 查询多个结果

android - 用于混合应用程序的 MbaaS(使用 cordova)

android - 移动设备上的 SignalR JavaScript 客户端

java - Android - 依赖和代码分离(调试/发布版本)

android - ListView 和表格布局有什么区别?

android - firebase-crashlytics-gradle 插件失败,异常 'googleServicesResourceRoot' 没有配置值

android - 无法使用 Android Studio 导入 ViewPagerIndicator 库

gradle - Android studio 意外锁文件协议(protocol)