Skip to content

Instantly share code, notes, and snippets.

@ducrohet
Last active August 29, 2015 14:06
Show Gist options
  • Save ducrohet/e0d854c54bd0ceeb7044 to your computer and use it in GitHub Desktop.
Save ducrohet/e0d854c54bd0ceeb7044 to your computer and use it in GitHub Desktop.
// need to create a signing task for all possible output
variant.outputs.each { output ->
// create a signing task for this
SignApk signTask = project.tasks.create("sign${output.name.capitalize()}MyApk", SignApk)
// setup task info
signTask.conventionMapping.inputFile = { output.packageApplication.outputFile }
signTask.outputFile = project.file("$project.buildDir/outputs/apk/${project.archivesBaseName}-${output.baseName}-unaligned.apk")
// other configuration of the signing task go here.
// setup task dependencies
signTask.dependsOn output.packageApplication
if (variant.buildType.isZipAlign()) {
// Because the variant is originally not signed, there is no zipAlign task.
// This will update the output.getOutputFile() result to match the output of this.
Task zipAlignTask = output.createZipAlignTask("zipAlign${output.name.capitalize()}",
signTask.outputFile,
project.file("$project.buildDir/outputs/apk/${project.archivesBaseName}-${output.baseName}.apk"))
// have to make it depend on the signing task. All other dependencies have been setup automatically.
zipAlignTask.dependsOn signTask
} else {
// reset the output of the output object.
output.setOutputFile(signTask.outputFile)
output.assemble.dependsOn signTask
}
}
// record in the model that the variant outputs are signed.
// This lets Studio knows that the apks can be deployed to a device
variant.outputsAreSigned = true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment