[2025] Solution with Explanation
In Oct 2024, a lot of the answers got a bit outdated for my case. Due to mixing up in the process, I lost some time. But it is actually very easy. Hence, I'll sum up what will actually work with explanation.
[Normally, you only need THIS FIRST PART]
First, let's look at what Flutter is suggesting.

For older versions than Flutter 3.19, you'd work on build.gradle file, which is the case in most of the answers.
But most likely you are using a newer version, so you must work on primarily settings.gradle. But... If you have already mixed up things like me you need to make sure to fix a few things.
The error says Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.7.1. > here, the binary version is what is written in your settings.gradle file for kotlin, and the expected version is associated with your AGP version i.e. your AGP version is not compatible with your kotlin version. You can find the version compatibility here with AGP vs Kotlin (KGP).
Now, open your settings.gradle file, and put the versions (that you want and compatible with each other) here [NOTE: I have used a different version than my error message (as per my interest) - 2.0.20 for Kotlin, and 8.1.1 for AGP] -
plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id 'com.android.application' version '8.1.1' apply false
id 'org.jetbrains.kotlin.android' version '2.0.20' apply false
}
[You may need THIS PART if your other settings are messed up]
Now, you need to make sure that you don't overwrite or mix up these values in other places.
- REMOVE (if present) this block from
project gradle (android/build.gradle). It is not required in newer version of Flutter or android project.

- Go to
app gradle (android/app/build.gradle). Make sure these 3 numbers match, if present (it threw an error until I matched them), otherwise ignore. I used Kotlin's JRE version 17 as jvmTarget.

- IMPORTANT open
graddle-wrapper.properties > MAKE SURE distributionUrl has the same version number as AGP. In my case, it's 8.1.1. distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-all.zip
- Now, clean the gradle caches (usually
C:\Users\NAME\.gradle\caches). Close your IDE if required.
- Open
project/android folder in Android Studio. Make sure you have Kotlin plugin installed on it (Settings > Plugins). Let Android Studio prepares the project. It will automatically download AGP and related files. If you have changed any project settings in File > Project Structure, make sure they are undone, and keep the defaults. Click the elephant icon at the top: Sync Project with the Gradle Files. It should complete the build normally. You can ignore AGP upgrade notification, if you are confident that you chose the compatible AGP in the earlier stage.
- From terminal,
flutter clean > flutter pub get > flutter run or flutter build apk --build-name=1.0 --build-number=1 --no-tree-shake-icons. These will complete the build normally as well.