Introduction

The Android Gradle Plugin (AGP) and Gradle wrapper must be compatible versions. When Flutter projects are created with an older template or when upgrading Flutter SDK, the Gradle plugin version in build.gradle may not match the Gradle wrapper version in gradle-wrapper.properties, causing build failures. This error is particularly common after upgrading to Flutter 3.16+ which requires AGP 8.x and Gradle 8.x.

Symptoms

  • Build fails with:
  • `
  • Error: The Android Gradle plugin version (7.4.2) is too old for the Gradle version (8.4).
  • Minimum supported Gradle version is 8.0.
  • `
  • Or:
  • `
  • Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
  • > Failed to notify project evaluation listener.
  • > The project is using an incompatible version of the Android Gradle plugin.
  • `
  • flutter run fails with Gradle sync errors
  • Android Studio shows red underline on Gradle files

Common Causes

  • Flutter project created with older SDK version using AGP 7.x
  • Upgrading Gradle wrapper without updating AGP version
  • Using Flutter 3.16+ which requires AGP 8.x but project still uses 7.x
  • Third-party plugins requiring different AGP versions
  • Corrupted Gradle cache

Step-by-Step Fix

  1. 1.Check current versions:
  2. 2.```bash
  3. 3.# Gradle wrapper version
  4. 4.cat android/gradle/wrapper/gradle-wrapper.properties
  5. 5.# Look for: distributionUrl=...gradle-8.4-all.zip

# AGP version cat android/build.gradle # Look for: classpath 'com.android.tools.build:gradle:8.1.0' ```

  1. 1.Update Gradle wrapper to match AGP:
  2. 2.```properties
  3. 3.# android/gradle/wrapper/gradle-wrapper.properties
  4. 4.distributionBase=GRADLE_USER_HOME
  5. 5.distributionPath=wrapper/dists
  6. 6.zipStoreBase=GRADLE_USER_HOME
  7. 7.zipStorePath=wrapper/dists
  8. 8.distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip
  9. 9.`
  10. 10.Update AGP version in build.gradle:
  11. 11.```groovy
  12. 12.// android/build.gradle
  13. 13.buildscript {
  14. 14.ext.kotlin_version = '1.9.10'
  15. 15.repositories {
  16. 16.google()
  17. 17.mavenCentral()
  18. 18.}
  19. 19.dependencies {
  20. 20.classpath 'com.android.tools.build:gradle:8.1.0'
  21. 21.classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
  22. 22.}
  23. 23.}
  24. 24.`
  25. 25.Update settings.gradle for AGP 8+ namespace:
  26. 26.```groovy
  27. 27.// android/app/build.gradle - add namespace
  28. 28.android {
  29. 29.namespace "com.example.myapp"
  30. 30.compileSdk 34

defaultConfig { applicationId "com.example.myapp" minSdk 21 targetSdk 34 versionCode 1 versionName "1.0" } } ```

  1. 1.Update kotlin-gradle-plugin if needed:
  2. 2.```groovy
  3. 3.// android/build.gradle
  4. 4.ext.kotlin_version = '1.9.10' // AGP 8.x requires Kotlin 1.8+
  5. 5.`
  6. 6.Clean and rebuild:
  7. 7.```bash
  8. 8.cd android
  9. 9../gradlew clean
  10. 10../gradlew wrapper
  11. 11.cd ..
  12. 12.flutter clean
  13. 13.flutter pub get
  14. 14.flutter run
  15. 15.`

AGP to Gradle Version Compatibility

AGP VersionMinimum GradleMaximum Gradle
8.3+8.48.6+
8.28.28.5
8.18.08.4
8.08.08.2
7.47.58.0

Prevention

  • Upgrade AGP and Gradle together
  • Keep compileSdk and targetSdk up to date
  • Run flutter doctor -v after SDK upgrades to check Android toolchain
  • Use flutter create . in existing projects to update Gradle templates
  • Pin AGP and Gradle versions in version control for team consistency