Home > Blockchain >  flutter error in android build.gradle , Could not run phased build action
flutter error in android build.gradle , Could not run phased build action

Time:10-16

I get an error in my android>build.gradle file.

The build.gradle file:

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

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

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
}

The error message:

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.

Update: When checking my Java version:

$ ./gradlew --version

------------------------------------------------------------
Gradle 7.4
------------------------------------------------------------

Build time:   2022-02-08 09:58:38 UTC
Revision:     f0d9291c04b90b59445041eaa75b2ee744162586

Kotlin:       1.5.31
Groovy:       3.0.9
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          11.0.16 (Oracle Corporation 11.0.16 11-LTS-199)
OS:           Windows 11 10.0 amd64

The error is marked at the first line on buildscript. Any idea what this is? It says that my java version is wrong but it have worked all the time and in all my other app it still works. Very strange to me. I use VScode if that makes any difference.

CodePudding user response:

vscode does not support older versions of jdk in some functions, switch to a higher version.

It is recommended to use jdk17, which can be downloaded from the Configure Java Runtime page.

enter image description here

CodePudding user response:

This bug resolved itself when I moved location of the flutter project. I guess something that a restart or flutter clean couldn’t reach got rebuilt when you move the location of the project. (Moved it to another folder)

  • Related