Search code examples
javaandroidfluttervisual-studio-codejava-11

Could not run phased build action using connection to Gradle distribution (Flutter)


Could not run phased build action using connection to Gradle distribution 'https://services.gradle.org/distributions/gradle-7.5-all.zip'.

org.gradle.api.ProjectConfigurationException: A problem occurred configuring root project 'android'.

A problem occurred configuring root project 'android'.

A problem occurred evaluating root project 'android'.

A problem occurred configuring project ':app'.

A problem occurred evaluating project ':app'.

Failed to apply plugin 'com.android.internal.application'.

Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.\nYour current JDK is located in C:\\Program Files\\Eclipse Foundation\\jdk-8.0.302.8-hotspot\\jre\nYou can try some of the following options:

  • changing the IDE settings.

  • changing the JAVA_HOME environment variable.

  • changing `org.gradle.java.home` in `gradle.properties`.

I tried changing the JAVA_HOME environment variable to "C:\Program Files\Eclipse Adoptium\jdk-11.0.18.10-hotspot", and also tried "F1" then JAVA: Install New JDK and install "OpenJDK11U-jdk_x64_windows_hotspot_11.0.18_10", I even deleted all java related programs from the control panel uninstall except "Eclipse temurin JDK with Hotspot 11.0.18+10(x64)" and "java(TM) SE Development Kit 11.0.17 (64-bit)" ... NOTE: I am using flutter on VS code


Solution

    • Set java.configuration.runtimes in vscode, configured it to java 11.

      https://code.visualstudio.com/docs/java/java-project#_configure-runtime-for-projects

      example:

      "java.configuration.runtimes": [
        {
          "name": "JavaSE-11",
          "path": "/usr/local/jdk-11.0.3",
          "sources" : "/usr/local/jdk-11.0.3/lib/src.zip",
          "javadoc" : "https://docs.oracle.com/en/java/javase/11/docs/api",
          "default":  true
         },
      ]
      
    • Set org.gradle.java.home in gradle.properties,

      org.gradle.java.home=C:/Program Files/Eclipse Adoptium/jdk-11.0.18.10-hotspot
      

      Make sure it is the correct java 11 installation path.