Resolving Execution Failed for Task ':path_provider_android:compileDebugJavaWithJavac' in Flutter
Problem Statement
When adding new packages to a Flutter project (e.g., provider
, google_fonts
, or others), you encounter a build failure with the recurring error:
Execution failed for task ':path_provider_android:compileDebugJavaWithJavac'
The error typically occurs after updating dependencies, Android Studio, or the Flutter SDK. It indicates a compatibility issue between the project’s JDK, Gradle, or Android SDK configuration. This can halt builds unexpectedly, even in previously functional projects.
Recommended Solutions
Apply these fixes to resolve JDK/Gradle compatibility conflicts:
Solution 1: Update Gradle and Java/Kotlin Versions (Recommended)
The most effective solution involves synchronizing JDK, Gradle, and Android plugin versions:
Update JDK Compatibility:
Modify/android/app/build.gradle
to enforce Java 17 compatibility:gradleandroid { compileOptions { sourceCompatibility JavaVersion.VERSION_17 targetCompatibility JavaVersion.VERSION_17 } kotlinOptions { jvmTarget = JavaVersion.VERSION_17.toString() } }
Upgrade Gradle Version:
ChangedistributionUrl
in/android/gradle/wrapper/gradle-wrapper.properties
:propertiesdistributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip
Update Android Plugin:
Adjust the plugin version in/android/settings.gradle
:gradleplugins { id "com.android.application" version "8.3.1" apply false // Keep other plugins consistent }
TIP
Use Gradle Compatibility Table to match plugin versions with Gradle.
Solution 2: Enable Core Library Desugaring
If Solution 1 yields Dependency 'X' requires core library desugaring
, enable desugaring:
- Modify
build.gradle
:gradleandroid { compileOptions { coreLibraryDesugaringEnabled true // Enable desugaring sourceCompatibility JavaVersion.VERSION_17 targetCompatibility JavaVersion.VERSION_17 } } dependencies { coreLibraryDesugaring "com.android.tools:desugar_jdk_libs:2.0.3" }
Alternative Troubleshooting Steps
If the error persists:
Clean Build Artifacts:
bashflutter clean rm -rf android/.gradle # Delete Gradle cache flutter pub get # Re-fetch dependencies
Verify JDK Installation:
- Ensure JDK 17 is installed.
- In Android Studio, configure SDK path:
File → Project Structure → SDK Location → JDK Location.
Check Package Compatibility:
Use VSCode Output Panel (Ctrl+Shift+U
) to detect dependency conflicts.
Conclusion
This error stems from JDK-Gradle-Android SDK version mismatches. The primary solution involves standardizing configurations:
- Enforce Java/Kotlin 17.
- Upgrade Gradle to 8.4 and the Android plugin to 8.3.1.
- Enable desugaring if dependencies require it.
Always review the Flutter GitHub Issues for similar reports. For new projects, use flutter create --android-language java .
to avoid Kotlin compatibility issues.