GLopez
GLopez

Reputation: 183

Android Studio 2.2 rename apk file

I have this code in my build.gradle to rename de apk but since Android Studio update to version 2.2 is no longer working.

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)
            }
        }
    }
}

I added some println to see if the newApk Name was OK, and I see no problem. Do you ,people , know any alternatives to accomplish this. I will be eternally grateful.

Upvotes: 0

Views: 320

Answers (1)

Veener
Veener

Reputation: 5201

Improves build performance by adopting a new default packaging pipeline which handles zipping, signing, and zipaligning in one task. You can revert to using the older packaging tools by adding android.useOldPackaging=true to yourgradle.properties file. While using the new packaging tool, the zipalignDebug task is not available. However, you can create one yourself by calling the createZipAlignTask(String taskName, File inputFile, File outputFile) method.

From release notes: https://developer.android.com/studio/releases/gradle-plugin.html#revisions

Upvotes: 2

Related Questions