Flutter Android Build: Fix AGP Version Error for compileSdk 35
Last updated: January 17, 2025 • Error first reported: September 4, 2024
Problem Statement
When building a Flutter app's Android release (APK or app bundle), you encounter this critical error:
[!] Using compileSdk 35 requires Android Gradle Plugin (AGP) 8.1.0 or higher.
Please upgrade to a newer AGP version...
The root cause is version incompatibility between:
compileSdkVersion 35
(Android 14+) specified in your project- An outdated Android Gradle Plugin (AGP < 8.1.0)
This prevents successful APK generation and requires either updating dependencies or temporarily downgrading compileSdk
.
Recommended Solution: Upgrade AGP and Gradle
Follow these steps to resolve the error permanently:
1. Update AGP and Kotlin Versions
Modify android/settings.gradle
to use compatible versions:
pluginManagement {
// ... existing code ...
plugins {
id("com.android.application") version "8.9.0" apply false
id("com.android.library") version "8.9.0" apply false
id("org.jetbrains.kotlin.android") version "2.1.10" apply false
// ... other plugins ...
}
}
TIP
- Use the official AGP-Gradle compatibility table to choose versions
- Current recommendation (2025): AGP 8.9.0 + Gradle 8.11.1
2. Update Gradle Distribution
Edit android/gradle/wrapper/gradle-wrapper.properties
:
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-all.zip
3. Fix JVM Target Compatibility
Add this to android/app/build.gradle
to prevent Kotlin/Java version conflicts:
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = "17"
}
}
4. Resolve NDK Issues (If Applicable)
In android/app/build.gradle
, explicitly set the NDK version:
android {
ndkVersion = "27.2.12479018" // Get latest from SDK Manager
}
TIP
Install the latest NDK via Android Studio:
Tools → SDK Manager → SDK Tools → NDK (Side by Side)
Final Build Commands
Execute these in your project root:
flutter clean
flutter pub get
cd android
./gradlew clean
cd ..
flutter build apk # or appbundle
WARNING
Always run flutter clean
after updating Gradle configurations to prevent caching issues.
Alternative Approach: Temporary compileSdk Downgrade
DANGER
Only use this as a short-term workaround - it bypasses newer Android features and security updates.
In android/app/build.gradle
, lower the compileSdkVersion
:
android {
compileSdkVersion 34 // Downgrade from 35
// Keep existing configurations
}
Additional Troubleshooting
Flutter Channel Conflicts
If you're on the master
channel, switch to stable:
flutter channel stable
flutter upgrade
Plugin Management Block Issues
For projects with older templates, simplify settings.gradle
by removing the pluginManagement
block and directly specify plugins:
plugins {
id("com.android.application") version "8.9.0" apply false
// ... other plugins ...
}
::: success Verification After fixes, confirm AGP version in build logs:
Android Gradle Plugin version: 8.9.0
:::
By upgrading AGP and Gradle to compatible versions, you resolve the core dependency conflict while ensuring access to the latest Android development features. Permanent upgrades are strongly favored over temporary SDK downgrades for production apps.