Just a gradle update needed
Fix broken Android Flutter build after Upgrade
You just upgraded your Flutter SDK and your Android app build doesn’t work anymore? Here’s the quick solution to fix the errors!
I have an old Flutter project created nearly 2 years ago for which I did an SDK upgrade today. Every Flutter SDK upgrade can be a challenge for such a project as there may be breaking changes. Here I want to show you how to fix an error about the Kotlin Gradle plugin.
When you build your application for Android and the error below appears, it is pretty simple to fix.
Though the Flutter Fix guidance is nice but didn’t help me at first. To fix the error, we first create a new Flutter dummy project with the command flutter create dummy
. Then we open the android/build.gradle
file of the dummy project and check the Gradle classpath.
classpath 'com.android.tools.build:gradle:4.1.0'
We open the same file in our actual project and change the gradle version to match the version in the dummy project.
Afterward, we do the same with the file android/gradle/wrapper/gradle-wrapper.properties
. Here we focus on the distributionUrl
which we most likely need to change.
After these two changes, your Android build should work again. If there are still errors, it might be due to Android SDK versions. Try changing compileSdkVersion
, minSdkVersion,
and targetSdkVersion
in build.gradle
according to the error message. Finally, your build should work as before.
Credits go to Suragch on StackOverflow who solved the problem.