doLast and android project

I’m late to upgrade Gradle, but today I woke up.

Now how should I rewrite this so it builds releases first and then executes my task?

Used to have

tasks.register('buildRelease') {
    dependsOn 'assembleRelease'
    group 'Build release and create manifest'
    description 'Builds all releases and creates manifest files for our update server'

    doLast {
        android.applicationVariants.configureEach { variant ->

But now it says for the last line:
Could not get unknown property 'android' for task ':app:buildRelease' of type org.gradle.api.DefaultTask.

I’ve tried dependsOn, finalizedBy also, but they fire too soon.