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?
- The user updates the Kotlin version of the plugin to match the IDE version per the warning.
- The user updates the android build tools gradle plugin per the warning
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:
- delete the ~/.gradle/cache directory
- delete the android/.gradle directory
- delete the project_dir/build dir
- ensure the
android/gradle/gradle-wrapper.properies
has the correct distributionUrl
(currently distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
)
- 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?