Although this question has been answered, I think it's worth explaining what is happening
---------
For the example:
The binary version of its metadata is 1.7.1, expected version is 1.5.1.
The `expected` version is the Kotlin for `kotlin-gradle-plugin`
The `binary` version is the what is downloaded (or previously compiled)
for `com.android.tools.build:gradle`
**<project_dir>/android/build.gradle**
buildscript {
ext.kotlin_version = '1.5.20' // <= expected version is 1.5.1
}
dependencies {
classpath 'com.android.tools.build:gradle:7.3.1' // downloads 1.7.1 Metadata
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // <= 1.5.20 used here
Why is this Happening So Much?
-------
1. The user updates the Kotlin version of the plugin to match the IDE version per the warning.
[![Warning from Android Studio to match Kotlin Versions][1]][1]
2. The user updates the android build tools gradle plugin per the warning
[![Warning about android build tools][2]][2]
***This is the WRONG version!***
Now you don't have any warnings, but the version suggested is `7.1.3` which is not the latest. (I don't know why it suggests this older version) `7.3.1` is currently the latest and is meta data `1.7.1`, so it will match the Kotlin version of `1.7.20` (which is also metadata `1.7.1`)
What else could be wrong?
-----
Due to caching, gradle may be using an older dependency before you updated. To start clean:
1. delete the ~/.gradle/cache directory
2. delete the android/.gradle directory
3. delete the project_dir/build dir
4. ensure the `android/gradle/gradle-wrapper.properies` has the correct `distributionUrl` (currently `distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip`)
5. from project_dir do `flutter build apk`
NOTE: your dependencies may need to be updated if their `com.android.tools.build:gradle` version is too old. Alternatively, both the kotlin and `tools:gradle` versions can be downgraded to compatible version that match metadata (although Android Studio will warn for that not matching the IDE Kotlin version)
How to Prevent this from happening Again?
-----
* Use the same Kotlin version as the IDE normally for `ext.kotlin_version`. see
[To see links please register here]
* Double check the `com.android.tools.build:gradle` version. See
[To see links please register here]
and
[To see links please register here]
[1]:
[2]: