Anonymous
Anonymous

Reputation: 9

Showing compile error in build.gradle "Could not run phased build action using connection to Gradle distribution". Saying "Java home is different."

I was building a flutter app in vscode which was working fine but suddenly it started showing this error in build.gradle:

Could not run phased build action using connection to Gradle distribution 'https://services.gradle.org/distributions/gradle-7.5-all.zip'.
The newly created daemon process has a different context than expected.
It won't be possible to reconnect to this daemon. Context mismatch: 
Java home is different.
Wanted: DefaultDaemonContext[uid=null,javaHome=/usr,daemonRegistryDir=/Users/rijuljain/.gradle/daemon,pid=82555,idleTimeout=null,priority=NORMAL,daemonOpts=--add-opens,java.base/java.util=ALL-UNNAMED,--add-opens,java.base/java.lang=ALL-UNNAMED,--add-opens,java.base/java.lang.invoke=ALL-UNNAMED,--add-opens,java.base/java.util=ALL-UNNAMED,--add-opens,java.prefs/java.util.prefs=ALL-UNNAMED,--add-opens,java.prefs/java.util.prefs=ALL-UNNAMED,--add-opens,java.base/java.nio.charset=ALL-UNNAMED,--add-opens,java.base/java.net=ALL-UNNAMED,--add-opens,java.base/java.util.concurrent.atomic=ALL-UNNAMED,-Xmx1536M,-Dfile.encoding=utf8,-Duser.country=IN,-Duser.language=en,-Duser.variant]
Actual: DefaultDaemonContext[uid=ccff97f5-924e-42fe-8259-9cdc23997e5b,javaHome=/Library/Java/JavaVirtualMachines/jdk-17.0.2.jdk/Contents/Home,daemonRegistryDir=/Users/rijuljain/.gradle/daemon,pid=82896,idleTimeout=10800000,priority=NORMAL,daemonOpts=--add-opens,java.base/java.util=ALL-UNNAMED,--add-opens,java.base/java.lang=ALL-UNNAMED,--add-opens,java.base/java.lang.invoke=ALL-UNNAMED,--add-opens,java.base/java.util=ALL-UNNAMED,--add-opens,java.prefs/java.util.prefs=ALL-UNNAMED,--add-opens,java.prefs/java.util.prefs=ALL-UNNAMED,--add-opens,java.base/java.nio.charset=ALL-UNNAMED,--add-opens,java.base/java.net=ALL-UNNAMED,--add-opens,java.base/java.util.concurrent.atomic=ALL-UNNAMED,-Xmx1536M,-Dfile.encoding=utf8,-Duser.country=IN,-Duser.language=en,-Duser.variant]Java(0)

java version: java 17.0.2 2022-01-18 LTS

my build.gradle:

buildscript {
    ext.kotlin_version = '1.7.10'
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:7.2.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.15'
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

.gradle/gradle-wrapper.properties

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip

It was showing the path was different, but the JAVA_HOME path is already there in my environment

export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk-17.0.2.jdk/Contents/Home"

please help me in solving this problem in vscode

Upvotes: 0

Views: 1100

Answers (2)

EissaB93
EissaB93

Reputation: 5

Disable every java extension in vscode and then restart that will fix it

Upvotes: 0

user3736412
user3736412

Reputation: 3

I had the same problem. It was solved for me simply by closing VS Code and restarting my MacBook, then re-opening VS Code.

Upvotes: 0

Related Questions