I’m rather new to gradle and i must admit that the syntax is far a way from self-explaining.
I made a copy-task as shown below and i ask me now is this the right way to do?
Or if this is an obsolete way because the most code-snippets uses another way.
(and what is the main difference to them?)
Thx for any further explanatons.
android.applicationVariants.all { variant ->
variant.outputs.all { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.apk')) {
def assembleTaskName = variant.getAssembleProvider().name
def mustRunAfterTask = "create${variant.name.capitalize()}ApkListingFileRedirect"
def newTargetName = theAppName + "-v" + variant.versionName + "-" + variant.name + ".apk"
def copyTask = project.tasks.create("copyAndRenameOutputAPKFile$assembleTaskName", Copy)
copyTask.from(outputFile.parent) {
include outputFileName
}
copyTask.into(rootProjDir)
copyTask.rename outputFileName , newTargetName
copyTask.dependsOn assembleTaskName
copyTask.mustRunAfter mustRunAfterTask
copyTask.doLast() {
println "Copied ${outputFileName} to ${newTargetName}"
}
tasks[assembleTaskName].finalizedBy = [copyTask]
}
}
}