Skip to content

Instantly share code, notes, and snippets.

@ocus
Created January 19, 2017 15:38
Show Gist options
  • Save ocus/8d7316b49cf1a94cfc0173101031a440 to your computer and use it in GitHub Desktop.
Save ocus/8d7316b49cf1a94cfc0173101031a440 to your computer and use it in GitHub Desktop.
Android Library Project - Copy AAR from build/outputs/aar/PROJECT-VARIANT.aar to build/PROJECT-VARIANT-VERSION_NAME.aar after each assembleVARIANT task
android.libraryVariants.all { variant ->
def variantName = variant.name.capitalize()
def copyTaskName = "copy${variantName}Artifacts"
def assembleTaskName = "assemble${variantName}"
task(copyTaskName, type: Copy, dependsOn: assembleTaskName, group: "build") {
variant.outputs.each { output ->
def newOutputName = output.outputFile.name.replace(".aar", "-" + android.defaultConfig.versionName + ".aar")
from(output.outputFile.parent) {
include output.outputFile.name
rename output.outputFile.name, newOutputName
}
}
into project.buildDir
}
project.tasks.getByName(assembleTaskName).finalizedBy(copyTaskName)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment