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 runfails 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.Check current versions:
- 2.```bash
- 3.# Gradle wrapper version
- 4.cat android/gradle/wrapper/gradle-wrapper.properties
- 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.Update Gradle wrapper to match AGP:
- 2.```properties
- 3.# android/gradle/wrapper/gradle-wrapper.properties
- 4.distributionBase=GRADLE_USER_HOME
- 5.distributionPath=wrapper/dists
- 6.zipStoreBase=GRADLE_USER_HOME
- 7.zipStorePath=wrapper/dists
- 8.distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip
- 9.
` - 10.Update AGP version in build.gradle:
- 11.```groovy
- 12.// android/build.gradle
- 13.buildscript {
- 14.ext.kotlin_version = '1.9.10'
- 15.repositories {
- 16.google()
- 17.mavenCentral()
- 18.}
- 19.dependencies {
- 20.classpath 'com.android.tools.build:gradle:8.1.0'
- 21.classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
- 22.}
- 23.}
- 24.
` - 25.Update settings.gradle for AGP 8+ namespace:
- 26.```groovy
- 27.// android/app/build.gradle - add namespace
- 28.android {
- 29.namespace "com.example.myapp"
- 30.compileSdk 34
defaultConfig { applicationId "com.example.myapp" minSdk 21 targetSdk 34 versionCode 1 versionName "1.0" } } ```
- 1.Update kotlin-gradle-plugin if needed:
- 2.```groovy
- 3.// android/build.gradle
- 4.ext.kotlin_version = '1.9.10' // AGP 8.x requires Kotlin 1.8+
- 5.
` - 6.Clean and rebuild:
- 7.```bash
- 8.cd android
- 9../gradlew clean
- 10../gradlew wrapper
- 11.cd ..
- 12.flutter clean
- 13.flutter pub get
- 14.flutter run
- 15.
`
AGP to Gradle Version Compatibility
| AGP Version | Minimum Gradle | Maximum Gradle |
|---|---|---|
| 8.3+ | 8.4 | 8.6+ |
| 8.2 | 8.2 | 8.5 |
| 8.1 | 8.0 | 8.4 |
| 8.0 | 8.0 | 8.2 |
| 7.4 | 7.5 | 8.0 |
Prevention
- Upgrade AGP and Gradle together
- Keep
compileSdkandtargetSdkup to date - Run
flutter doctor -vafter 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