Skip to content

Commit

Permalink
自定义输出APK名字修改
Browse files Browse the repository at this point in the history
  • Loading branch information
maning committed Dec 29, 2017
1 parent 3e26f19 commit 8672814
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,6 @@ android {
shrinkResources true
proguardFiles customerproguardFile.path
buildConfigField "boolean", "LOG_DEBUG", "false"
// 自定义输出配置
// android.applicationVariants.all { variant ->
// variant.outputs.each { output ->
// def outputFile = output.outputFile
// if (outputFile != null && outputFile.name.endsWith('.apk')) {
// // 输出apk名称为xxx_release_v1.0_wandoujia_time.apk
// def fileName = "gankmm_${variant.buildType.name}_v${defaultConfig.versionName}_${variant.productFlavors[0].name}_${buildTime()}.apk"
// outputFileName = fileName
// }
// }
// }
}
debug {
//混淆
Expand All @@ -79,12 +68,34 @@ android {
}
}

//修改apk名
applicationVariants.all { variant ->
variant.outputs.all { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('release.apk')) {
// 输出apk名称为GankMM_yingyongbao_v1.0.0_2017-12-29-21_23_30_release.apk
def fileName = "GankMM_${variant.flavorName}_v${variant.versionName}_${releaseTime()}_release.apk"
outputFileName = new File(fileName)
}
if (outputFile != null && outputFile.name.endsWith('debug.apk')) {
// 输出apk名称为GankMM_yingyongbao_v1.0.0_2017-12-29_debug.apk
def fileName = "GankMM_${variant.flavorName}_v${variant.versionName}_${debugTime()}_debug.apk"
outputFileName = new File(fileName)
}
}
}
}

static def buildTime() {
return new Date().format("yyyy-MM-dd-HH-mm", TimeZone.getDefault())//包含时分秒
//时间字符串方法
def debugTime() {
return new Date().format("yyyy-MM-dd", TimeZone.getTimeZone("GMT+8:00"))
}

def releaseTime() {
return new Date().format("yyyy-MM-dd_HH_mm_ss", TimeZone.getTimeZone("GMT+8:00"))
}


repositories {
flatDir {
dirs 'libs'
Expand Down

0 comments on commit 8672814

Please sign in to comment.