Last active
April 3, 2019 13:53
-
-
Save uOOOO/fbc551f9636700027b905f6c9f73e251 to your computer and use it in GitHub Desktop.
Archive APK and Proguard map files to artifact directory
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 deleteBuildDir(def variant) { | |
| delete variant.packageApplicationProvider.get().outputDirectory | |
| } | |
| def setBuildTime() { | |
| project.ext.set("buildTime", System.currentTimeMillis()) | |
| } | |
| def getBuildTime() { | |
| def date = new Date(project.ext.buildTime) | |
| return date.format('yyyy.MM.dd-HH.mm.ss') | |
| } | |
| def createFileName(def variant) { | |
| return "${variant.applicationId}".replace('.debug', '').replace('.mock', '') + | |
| "-${variant.buildType.name}-${variant.versionName}-${getBuildTime()}" | |
| } | |
| def createApkName(def variant) { | |
| return createFileName(variant) + '.apk' | |
| } | |
| def createMapZipName(def variant) { | |
| return createFileName(variant) + '-mapping.zip' | |
| } | |
| def zipMappingFiles(def variant) { | |
| // zip and copy proguard mapping files | |
| if (variant.getBuildType().isMinifyEnabled()) { | |
| def dest = variant.packageApplicationProvider.get().outputDirectory.path + '/' + createMapZipName(variant) | |
| ant.zip(destfile: dest) { | |
| fileset(dir: variant.mappingFile.parentFile) { | |
| include(name: '**/*.txt') | |
| } | |
| } | |
| } | |
| } | |
| def createArtifactsPath() { | |
| return "${project.projectDir}/artifacts/${getBuildTime()}" | |
| } | |
| def copyArtifacts(def variant) { | |
| println(variant.packageApplicationProvider.get().outputDirectory) | |
| copy { | |
| from variant.packageApplicationProvider.get().outputDirectory | |
| into createArtifactsPath() | |
| include '*.apk', '*.zip' | |
| } | |
| } | |
| def registerArtifactTasks() { | |
| android.applicationVariants.all { variant -> | |
| setBuildTime() | |
| variant.outputs.all { | |
| deleteBuildDir(variant) | |
| outputFileName = createApkName(variant) | |
| getAssembleProvider().configure { | |
| doLast { | |
| zipMappingFiles(variant) | |
| copyArtifacts(variant) | |
| } | |
| } | |
| } | |
| } | |
| } | |
| ext { | |
| registerArtifactTasks = this.®isterArtifactTasks | |
| } |
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
| apply from: 'archiveApk.gradle' | |
| android { | |
| ...... | |
| afterEvaluate { | |
| registerArtifactTasks() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment