I am trying to automatically copy the apk file generated by Android Studio to my PC desktop as well. To do this, I add the following code to build.gradle (module):
android {
...
buildTypes {
...
debug {
android.applicationVariants.all { variant ->
variant.outputs.all {output ->
outputFileName = new File(parent.name + ".apk")
def taskSuffix = variant.name.capitalize()
def assembleTaskName = "assemble$taskSuffix"
if (tasks.findByName(assembleTaskName)) {
def copyAPKFolderTask = tasks.create(name: "archive$taskSuffix", type: org.gradle.api.tasks.Copy) {
from "$buildDir/outputs/apk/debug/"
into "C:/Users/Bernhard/Desktop/"
include parent.name + ".apk"
}
tasks[assembleTaskName].finalizedBy = [copyAPKFolderTask]
}
}
}
}
}
}
This works, BUT the very first time it takes up to 10 minutes for the code to be processed. From then on it only takes seconds for a revised apk file to be copied to the desktop. I am grateful for any help.
Thanks, Bernhard