2

I can't run my app anymore since i tried to change the target sdk from 33 to 34. Now even when I change it back I get the same error:


FAILURE: Build failed with an exception.

  • Where: Build file 'C:\Users\dicov\Downloads\Flutter-Dating-App-master\android\build.gradle' line: 28

  • 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)'


This is my build.gradle

    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 keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}


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

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



android {
    compileSdkVersion 34
    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'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "...."
        // You can update the following values to match your application needs.
        // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
        minSdkVersion 24
        targetSdkVersion 33
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName

    }

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

}

flutter {
    source '../..'
}

dependencies {
    implementation platform('com.google.firebase:firebase-bom:32.0.0')
    implementation 'com.google.firebase:firebase-analytics'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.22"
    implementation 'com.google.android.gms:play-services-ads:23.1.0'
}

And this my manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="......">

    <!-- Internet permission -->
    <uses-permission android:name="android.permission.INTERNET"/>

    <!-- Google Mobile Ads ID permission -->
    <uses-permission android:name="com.google.android.gms.permission.AD_ID"/>

    <!-- Google Play Billing permission -->
    <uses-permission android:name="com.android.vending.BILLING" />

    <!-- Foreground service special use permission -->
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE"/>

    <application
        android:label="Smash or Pass"
        android:name="${applicationName}"
        android:icon="@mipmap/launcher_icon">

        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">

            <meta-data
                android:name="io.flutter.embedding.android.NormalTheme"
                android:resource="@style/NormalTheme"
                />

            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>

            <service
                android:name="Smash or pass"
                android:foregroundServiceType="specialUse">
                <property
                    android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
                    android:value="My foreground service is showing pictures but I don't use the packages that is needed for the Media Projection foreground type"
                    />
            </service>
        </activity>

        <!-- Don't delete the meta-data below. This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />

        <!-- Google Mobile Ads Application ID -->
        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="real one here"/>
    </application>
</manifest>

This is my build.gradle android level:

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

    }

    dependencies {
        classpath 'com.android.tools.build:gradle:7.4.2'
        classpath 'com.google.gms:google-services:4.4.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.0"
    }
}

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
}

And the android SDK upgrade assistant isn't helping me either, I do everything it says and it still doesn't verify the components I did do to upgrade my SDK from 33 to 34.

Can anyone please help me, thank you.

13
  • Did you try the following commands in terminal? flutter clean, flutter pub get
    – Texv
    Commented Jul 6 at 16:29
  • I have just tried these commands, but i still get the same error. Commented Jul 6 at 18:11
  • 2
    You are showing us the app level build.gradle, but the error is talking about the project level (C:...\android\build.gradle) can you show us the other build.gradle? there must have been changes made automatically when you upgraded your sdk
    – Texv
    Commented Jul 7 at 6:02
  • I have added the build.gradle on android level Commented Jul 7 at 10:34
  • 1
    Yes, basically anything can be responsible, the error should have more details after the "Failed to notify project evaluation listener. " part. There should be a full stacktrace which should have the root issue at the bottom ("caused by SomeException"), maybe that needs to be enabled to become visible (hints stackoverflow.com/q/21674091 for example). Strange build errors are often caused by version mismatches. Java Version, Gradle Version, Gradle plugin versions, flutter version, flutter pakage versions, ...
    – zapl
    Commented Jul 9 at 17:03

7 Answers 7

1

Please add the target sdk version and compileSdkVersion 33 to 34. after open the project android folder for android studio and upgrade your all the gradel and kotline version.

targetsdk

compileSdkVersion

2
  • I have updated my gradel and kotlin version in the build.gradle but i still get the same error. Commented Jul 11 at 21:36
  • Flutter clean and flutter pub get. please check your android studio version. my android studio version is Jellyfish | 2023.3.1 (Apr 2024). Please try to used lates android studio. Commented Jul 12 at 7:46
0

Please make a backup copy of your project then try the following steps to update your project with SDK 34:

In /android/app/build.gradle

android {
    compileSdk = 34
    ndkVersion = flutter.ndkVersion
}

Upgrade gradle version in your /android/build.gradle file:

dependencies {
        classpath 'com.android.tools.build:gradle:8.1.4'
}    

Upgrade the Gradle wrapper in distributionUrl in /android/gradle/wrapper/gradle-wrapper.properties:

distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-all.zip

On Android Studio settings navigate to Appearance & Behavior > System Settings > Android SDK > SDK Tools > make sure 34.0.0 is installed.

After those changes, run the following commands in order:

flutter clean

flutter pub get

cd android

./gradlew clean

In the above command, it can take up to 5 to 7 minutes to complete depending on your internet speed. Please be patient. Also remember to cd android directory first and NOT do something like ./android/gradlew clean, otherwise it will not find the necessary files.

./gradlew build

cd ../

Now run your project and see if it works. If not, please run with verbose and update your question with some more details regarding the error.

flutter run --verbose --debug

0

Try to update your root level gradle, app level gradle and the gradle settings as per this article. It needed to be updated with the new flutter versions. https://docs.flutter.dev/release/breaking-changes/flutter-gradle-plugin-apply

0

If you still have the issue may this help you, first delete the pubspec.lock and then

flutter clean
flutter pub get

Sometimes when we update pubspec.yaml or change any dependency in the core android folder pubspec.lock will not be updated, so we need to update it by deleting and re-creating.

0

targetSdkVersion 33 to targetSdkVersion 34

0

Maybe you can try to update your gradle version which compatible with sdk 34.

When you upgrade the compile SDK to version 34, it necessitates upgrading the Gradle plugin version to at least 8.1.1 and the Gradle version to 8.1.

0

A namespace was required and that solved the error for now

Not the answer you're looking for? Browse other questions tagged or ask your own question.