Skip to content

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.


Apply these fixes to resolve JDK/Gradle compatibility conflicts:

The most effective solution involves synchronizing JDK, Gradle, and Android plugin versions:

  1. Update JDK Compatibility:
    Modify /android/app/build.gradle to enforce Java 17 compatibility:

    gradle
    android {
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_17
            targetCompatibility JavaVersion.VERSION_17
        }
        kotlinOptions {
            jvmTarget = JavaVersion.VERSION_17.toString()
        }
    }
  2. Upgrade Gradle Version:
    Change distributionUrl in /android/gradle/wrapper/gradle-wrapper.properties:

    properties
    distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip
  3. Update Android Plugin:
    Adjust the plugin version in /android/settings.gradle:

    gradle
    plugins {
        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:

  1. Modify build.gradle:
    gradle
    android {
        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:

  1. Clean Build Artifacts:

    bash
    flutter clean
    rm -rf android/.gradle  # Delete Gradle cache
    flutter pub get        # Re-fetch dependencies
  2. Verify JDK Installation:

    • Ensure JDK 17 is installed.
    • In Android Studio, configure SDK path:
      File → Project Structure → SDK Location → JDK Location.
  3. 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:

  1. Enforce Java/Kotlin 17.
  2. Upgrade Gradle to 8.4 and the Android plugin to 8.3.1.
  3. 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.