A problem occurred evaluating root project 'android'. > A problem occurred configuring project ':app'. > Failed to notify project evaluation listener

Anyone know why it keep showing this error

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\Users\wongp\Downloads\ServiceX\android\build.gradle' line: 36

* What went wrong:
A problem occurred evaluating root project 'android'.
> A problem occurred configuring project ':app'.
   > Failed to notify project evaluation listener.
      > 'com.android.build.api.variant.SourceDirectories$Flat com.android.build.api.variant.Sources.getByName(java.lang.String)'

Here is my code:
Andriod\build.gradle


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

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

tasks.register("clean", Delete) {
    delete rootProject.buildDir
}

app\build.gradle

plugins {
    id "com.android.application"
    id "dev.flutter.flutter-gradle-plugin"
    id 'kotlin-android'
    id "com.google.gms.google-services"
//    id "com.google.firebase.crashlytics"
}

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

android {
    namespace "com.example.demo_app"
    compileSdkVersion flutter.compileSdkVersion
    ndkVersion flutter.ndkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        applicationId "com.WPS.ServiceX"
        minSdkVersion 21
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    buildTypes {
        release {
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.20"
    implementation(platform("com.google.firebase:firebase-bom:32.8.1"))
    implementation("com.google.firebase:firebase-analytics")
}

How could I solve this trouble?

PS C:\Users\wongp\Music\E-commerce-Complete-Flutter-UI-master\android> ./gradlew signingReport

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.
-----------
* Where:
Build file 'C:\Users\wongp\Music\E-commerce-Complete-Flutter-UI-master\android\build.gradle' line: 53

* What went wrong:
A problem occurred evaluating root project 'android'.
> Cannot add task 'clean' as a task with that name already exists.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
==============================================================================

2: Task failed with an exception.
-----------
* What went wrong:
A problem occurred configuring root project 'android'.
> compileSdkVersion is not specified. Please add it to build.gradle

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
==============================================================================

* Get more help at https://help.gradle.org

BUILD FAILED in 1s
pluginManagement {
    def flutterSdkPath = {
        def properties = new Properties()
        file("local.properties").withInputStream { properties.load(it) }
        def flutterSdkPath = properties.getProperty("flutter.sdk")
        assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
        return flutterSdkPath
    }()

    includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")

    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}

plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    id "com.android.application" version "7.2.0" apply false
    id 'com.google.gms.google-services' version '4.4.1' apply false
    id "org.jetbrains.kotlin.android" version "1.7.20" apply false
}

include ":app"

Your error says you try to register a second task with name clean.
Don’t do that, but configure the existing task instead.

I tried to remove this

tasks.register("clean", Delete) {
    delete rootProject.buildDir

from andriod\build.gradle, but it still show the same problem, wheares when i removed the firebase code from the 3 files, it will works, so I thinks the issus is because of the firebase. Dont know why I already follow the tutorial from firebase authentication, but the error kept there…

Well, your error said

Cannot add task ‘clean’ as a task with that name already exists.

And that is at least the only place in what you shared where you register a clean task.
You probably apply some plugin there that also registers a clean task.
So yes, remove that, or configure the existing clean task to delete that additional directory, if it is not anyway what happens already.

Can you share a build --scan?

Teacher I try to migrate my file types from Groovy to Kotlin, but there are lots of problem come out…

I try to migrate my file types from Groovy to Kotlin

Very good idea. :slight_smile:
You instantly get type-safe build scripts, actually helpful error messages if you mess up the syntax, and amazingly better IDE support if you use a good IDE like IntelliJ IDEA or Android Studio. :slight_smile:

Any guideline/tutorial in teaching a proper way to migrate to Kotlin? I followed some of the google/youtube tutorial, but end up a lots of error comes out…

PS C:\Users\wongp\Downloads\ServiceX> gradle assembleDebug --scan
Starting a Gradle Daemon, 1 incompatible and 1 stopped Daemons could not be reused, use --status for details

> IDLE
FAILURE: Build failed with an exception.

* What went wrong:
Directory 'C:\Users\wongp\Downloads\ServiceX' does not contain a Gradle build.

A Gradle build should contain a 'settings.gradle' or 'settings.gradle.kts' file in its root directory. It may also contain a 'build.gradle' or 'build.gradle.kts' file.

To create a new Gradle build in this directory run 'gradle init'

For more information about the 'init' task, please refer to https://docs.gradle.org/8.5/userguide/build_init_plugin.html in the Gradle documentation.

For more details on creating a Gradle build, please refer to https://docs.gradle.org/8.5/userguide/tutorial_using_tasks.html in the Gradle documentation.

* Try:
> Run gradle init to create a new Gradle build in this directory.
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Get more help at https://help.gradle.org.

BUILD FAILED in 20s

Any guideline/tutorial in teaching a proper way to migrate to Kotlin?

Only the official docs:
https://docs.gradle.org/current/userguide/migrating_from_groovy_to_kotlin_dsl.html

Directory ‘C:\Users\wongp\Downloads\ServiceX’ does not contain a Gradle build.

That was not too helpful :slight_smile:

1 Like