Last active
August 29, 2015 14:06
-
-
Save zhengzhou/e9b05263f2fa47868fd6 to your computer and use it in GitHub Desktop.
androidStudio 运行时重命名apk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def outPut = "$buildDir/outputs/apk/" | |
def channel_id = -1000 | |
def buildVariant = '-debug.' | |
task getChannelId << { | |
def manifest = new XmlParser().parse("2.1.1/AndroidManifest.xml") | |
def androidSchemas = new groovy.xml.Namespace("http://schemas.android.com/apk/res/android", 'android') | |
manifest.application.('meta-data').each{ | |
def nodeName = it.attribute(androidSchemas.name) | |
if(nodeName.equals('xinyi_id')) | |
channel_id = it.attribute(androidSchemas.value) | |
} | |
version = manifest.attribute(androidSchemas.versionName) | |
} | |
task renameOutput <<{ | |
def dateStr = new Date().format('yyyy.MM.dd_HH.mm') | |
def innerName = "_${version}_${dateStr}_${channel_id}." | |
file(outPut).listFiles().each {File apkFile -> | |
if(apkFile.name.contains(buildVariant)) { | |
def newName = apkFile.name.replace(buildVariant,innerName); | |
def fileDir = file("$buildDir/"+buildVariant.subSequence(1,buildVariant.length()-1)) | |
copy { | |
from apkFile | |
into fileDir | |
} | |
String originName = "$fileDir/$project.name${buildVariant}apk" | |
file(originName).renameTo(file("$fileDir/$newName")) | |
println("打包出文件:$fileDir/$newName ") | |
} | |
} | |
} | |
assembleDebug <<{ | |
buildVariant = "-debug." | |
getChannelId.execute() | |
renameOutput.execute() | |
} | |
assembleRelease <<{ | |
buildVariant = '-release.' | |
getChannelId.execute() | |
renameOutput.execute() | |
} | |
task test <<{ | |
println("task last") | |
getChannelId.execute() | |
renameOutput.execute() | |
} | |
uploadArchives{ | |
repositories{ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
apk文件生成到 build/debug/项目名+版本名+日期+渠道号.apk中
apk文件生成到 build/release/项目名+版本名+日期+渠道号.apk中