2016-09-21 87 views
0

我有这个代码在我的build.gradle重命名德apk,但自从Android Studio更新到版本2.2不再工作。Android Studio 2.2重命名apk文件

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名称是否可以,并且我没有发现问题。你们是否知道任何替代方案来实现这一目标?我会永远感激。

+0

尝试android.useOldPackaging =真。 https://developer.android.com/studio/releases/gradle-plugin.html#revisions – Veener

回答

2

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

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

+1

这工作,谢谢。 – GLopez