Android Studio: Copying the build apk file on desktop

Months ago, I managed (with the help of Google) that Android Studio writes the build apk file on the desktop of my windows laptop (instead of using the directory app\build\outputs\apk\debug) by adding the following code in the file build.gradle:

debug {
    android.applicationVariants.all { variant ->
        variant.outputs.all {output ->
            outputFileName = new File( + ".apk")
            def taskSuffix =
            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 + ".apk"
                tasks[assembleTaskName].finalizedBy = [copyAPKFolderTask]

That works, BUT the very first time (or after any update of Android Studio or Gradle) it takes > 10 minutes to build the apk file (instead of some seconds as the next times). What is the reason why? How to prevent this? I’m very new in Gradle.
Thanks, Bernhard