project.tasks.configureEach error AGP 8.2

hi
Can someone help me with this issue?

when add code to gradle android project, project no sync
AGP v8.2.2
Gradle v8.6

android.applicationVariants.configureEach { variant ->
    def uploadTaskName = "upload${variant.name.capitalize()}Symbols"
    project.tasks.configureEach { task ->
        if (task.name == uploadTaskName) {
            variant.assembleProvider.configure { finalizedBy(task) } // If you use apk
            project.tasks.named("bundle${variant.name.capitalize()}") { finalizedBy(task) } // If you use aab
        }
    }
}

error:

Maybe it works better if you use the more idiomatic

tasks.matching { it.name == uploadTaskName }.configureEach {
    ...
}

Or if that task has a specific type, even better

tasks.withType(...).matching { it.name == uploadTaskName }.configureEach {
    ...
}