As mentioned in other answers this is caused by the project using a different gradle version after an Android Studio update or using in a newer installation, I installed a fresh copy of flutter and android studio in a new pc to compare projects, extracted the differences in the configuration and made the following changes to the project:
in the android/gradle/wrapper/gradle-wrapper.properties update the gradle files; from(example):
distributionUrl=https://services.gradle.org/distributions/gradle-6.7-all.zip
to:
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-all.zip
(inverting the numbers was just a coincidence)
in the android/gradle/build.gradle file update the buildscript.dependencies to gradle version 7.2.0; from(example):
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
to:
dependencies {
classpath 'com.android.tools.build:gradle:7.2.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
(the wrapper and properties version don't match identically)
3)in the android/local.properties make sure you have the correct minSdkVersion and compileSdkVersion;from(example):
flutter.minSdkVersion=26
flutter.targetSdkVersion=31
to:
flutter.minSdkVersion=26
flutter.targetSdkVersion=33
flutter.compileSdkVersion=33
run:
flutter pub outdated
flutter pub upgrade
flutter clean
flutter pub get
Note: you may have to replace packages due to compatibility, in my case I had to drop package_info for package_info_plus and upgraded other packages.