skip to Main Content

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:UsersdicovDownloadsFlutter-Dating-App-masterandroidbuild.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 pleas help me, thank you.

3

Answers


  1. 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

    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
  3. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search