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!

xeladu
2 min readFeb 9, 2022
Photo by Elisa Ventur on Unsplash

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.

Build errors for Android after Flutter SDK upgrade 1

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.

Flutter build.gradle

Credits go to Suragch on StackOverflow who solved the problem.

--

--

xeladu
xeladu

Written by xeladu

Flutter and Firebase expert, blogger on QuickCoder.org, find my ebooks and freebies on shop.quickcoder.org, contact me on me.quickcoder.org!

No responses yet