My flutter app was not working in Visual Studio Code today and I got this error:
Could not run phased build action using connection to Gradle distribution 'https://services.gradle.org/distributions/gradle-7.4-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.
You 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 did some research and came across this great thread on StackOverflow and have been trying to get mine to work.
I downloaded the latest Java and updated it in Android Studio:
That fixed on error. I used to get the error twice, Now I onlg get this one:
Could not run phased build action using connection to Gradle distribution 'https://services.gradle.org/distributions/gradle-7.4-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.
You 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 then decided to try updating gradle.properties
and I added the path to my new Java download like this:
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
org.gradle.java.home=/Library/Java/JavaVirtualMachines/jdk-18.0.2.jdk/Contents/Home
I got that path from running /usr/libexec/java_home -v 11
in a terminal
I then ran flutter clean and a pub get and I am still receiving the same error. No dice..
Update:
Ran java --version
in terminal withing Visual Studio code and got this:
openjdk 11.0.16 2022-07-19
OpenJDK Runtime Environment Temurin-11.0.16+8 (build 11.0.16+8)
OpenJDK 64-Bit Server VM Temurin-11.0.16+8 (build 11.0.16+8, mixed mode)
Update2:
So now this is super odd. I have narrowed this down to only affecting Visual Studio Code. Android Studio, runs my app fine...