Skip to content

Cannot run Project.afterEvaluate(Action) when the project is already evaluated. #180899

@Priyanshu-techind

Description

@Priyanshu-techind

Steps to reproduce

This issue is related to a previously closed and locked issue:
#175121

The issue was closed due to inactivity, but the problem still exists.

Observed behavior

Gradle fails with:
FAILURE: Build failed with an exception.

  • Where:
    Build file 'D:\Flutter\achvr-mobile\android\app\build.gradle' line: 4

  • What went wrong:
    An exception occurred applying plugin request [id: 'dev.flutter.flutter-gradle-plugin']

Failed to apply plugin 'dev.flutter.flutter-gradle-plugin'.
Cannot run Project.afterEvaluate(Action) when the project is already evaluated.

  • 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 40s
Error: Gradle task assembleDebug failed with exit code 1

Expected results

The Android project should build successfully using Gradle 8.x and the
current Flutter Android Gradle plugin without lifecycle errors.

Actual results

The build fails during Gradle configuration with the error:

Cannot run Project.afterEvaluate(Action) when the project is already evaluated

This prevents running the app in debug or release mode.

Code sample

Code sample this is my code of android/app/build.gradle
plugins {
    id "com.android.application"
    id "kotlin-android"
    id "dev.flutter.flutter-gradle-plugin"
    id "com.google.gms.google-services"
}

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

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

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

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

// Key store file for sign apk
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

android {
    namespace 'com.test'
    compileSdk 36

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
        coreLibraryDesugaringEnabled true
    }
    lintOptions {
        disable 'InvalidPackage'
        disable "Instantiatable"
        checkReleaseBuilds false
        abortOnError false
    }
    kotlinOptions {
        jvmTarget = '17'
    }

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

    defaultConfig {
        applicationId "com.test"
        minSdk 24
        targetSdk 36
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }


    signingConfigs {
        debug {

        }
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
            storePassword keystoreProperties['storePassword']
        }
    }

    buildTypes {
        debug {
            signingConfig signingConfigs.debug
        }
        release {
            signingConfig signingConfigs.release
            minifyEnabled false
            shrinkResources false
            crunchPngs false // or true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'

        }
    }
}

flutter {
    source '../..'
}

dependencies {
    coreLibraryDesugaring "com.android.tools:desugar_jdk_libs:2.1.5"
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.multidex:multidex:2.0.1'
    implementation platform('com.google.firebase:firebase-bom:31.2.0')
    implementation 'com.google.firebase:firebase-analytics-ktx'
    implementation 'com.google.firebase:firebase-auth-ktx'
    implementation 'com.google.firebase:firebase-firestore-ktx'
   // implementation 'com.facebook.android:facebook-login:latest.release'
    //implementation "com.facebook.android:facebook-login:15.0.2"
}

Screenshots or Video

Screenshots / Video demonstration Image

Logs

Logs
FAILURE: Build failed with an exception.

* Where:
Build file 'D:\Flutter\achvr-mobile\android\app\build.gradle' line: 4

* What went wrong:
An exception occurred applying plugin request [id: 'dev.flutter.flutter-gradle-plugin']
> Failed to apply plugin 'dev.flutter.flutter-gradle-plugin'.
   > Cannot run Project.afterEvaluate(Action) when the project is already evaluated.

* 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 40s
Error: Gradle task assembleDebug failed with exit code 1

Flutter Doctor output

Doctor output
[√] Flutter (Channel main, 3.40.0-0.2.pre, on Microsoft Windows [Version 10.0.26200.7462], locale en-IN) [6.4s]
    • Flutter version 3.40.0-0.2.pre on channel main at C:\dev\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 8f94cb0d8f (4 months ago), 2025-09-17 16:00:23 +0100
    • Engine revision 4de430f668
    • Dart version 3.10.0 (build 3.10.0-213.0.dev)
    • DevTools version 2.50.0
    • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations, enable-native-assets,
      omit-legacy-version-file, enable-lldb-debugging

[√] Windows Version (Windows 11 or higher, 25H2, 2009) [4.4s]

[√] Android toolchain - develop for Android devices (Android SDK version 36.0.0) [8.9s]
    • Android SDK at C:\dev\Android\Sdk
    • Emulator version 35.6.11.0 (build_id 13610412) (CL:N/A)
    • Platform android-36, build-tools 36.0.0
    • Java binary at: C:\Program Files\Java\jdk-17\bin\java
      This JDK is specified in your Flutter configuration.
      To change the current JDK, run: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version Java(TM) SE Runtime Environment (build 17.0.12+8-LTS-286)
    • All Android licenses accepted.

[√] Chrome - develop for the web [55ms]
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[X] Visual Studio - develop Windows apps [51ms]
    X Visual Studio not installed; this is necessary to develop Windows apps.
      Download at https://visualstudio.microsoft.com/downloads/.
      Please install the "Desktop development with C++" workload, including all of its default components

[√] Connected device (4 available) [1,412ms]
    • RMX2001 (wireless) (mobile) • adb-XKHYQWZ5LNJ7JJMF-dxZlA3._adb-tls-connect._tcp • android-arm64  • Android 11 (API 30)
    • Windows (desktop)           • windows                                           • windows-x64    • Microsoft Windows [Version 10.0.26200.7462]
    • Chrome (web)                • chrome                                            • web-javascript • Google Chrome 143.0.7499.193
    • Edge (web)                  • edge                                              • web-javascript • Microsoft Edge 143.0.3650.139

[√] Network resources [950ms]
    • All expected network resources are available.

! Doctor found issues in 1 category.
PS D:\Flutter\ach

Metadata

Metadata

Assignees

Labels

platform-androidAndroid applications specificallyt: gradle"flutter build" and "flutter run" on Androidteam-androidOwned by Android platform teamtoolAffects the "flutter" command-line tool. See also t: labels.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions