skip to Main Content

I am trying to run the flutter application on the android studio before now all works perfectly but after I changed my targetSdkVersion to targetSdkVersion 31 I started getting this error that says

Execution failed for task ':app:checkDebugAarMetadata'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > Could not resolve com.google.firebase:firebase-core:25.12.0.
     Required by:
         project :app
      > No cached version of com.google.firebase:firebase-core:25.12.0 available for offline mode.

And google-services.json is available in my project. My pubspec.yaml for firebase_message is firebase_messaging: ^7.0.3, android/build.gradledependencies is

buildscript {
    ext.kotlin_version = '1.3.61'
    repositories {
        google()
        jcenter()
        mavenCentral()  // Maven Central repository
    }

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


``` and my ```app/build.gradle``` dependencies is 
dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    testImplementation 'junit:junit:4.12'
    implementation 'com.google.firebase:firebase-analytics'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.android.support:multidex:1.0.3'

    implementation 'com.google.firebase:firebase-core:11.0.4'
    implementation platform('com.google.firebase:firebase-bom:31.0.2')

}

Thanks, in advance, please let me know if there is any information is needed

I tried to clean the project, pub upgrade, pub get, flutter upgrade, and even tried downloading a new version of firebase_messaging and pasting it inside the project still the same error.

2

Answers


  1. Chosen as BEST ANSWER

    So I was able to solve this by first updating my firebase_messaging version in pubspec.yaml to firebase_messaging: ^13.0.4 And android/build.gradle dependencies is

    
    buildscript {
        ext.kotlin_version = '1.5.31'
        repositories {
            google()
            jcenter()
            mavenCentral()  // Maven Central repository
        }
    
        dependencies {
            classpath 'com.android.tools.build:gradle:4.1.3'
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
            classpath 'com.google.gms:google-services:4.3.13'
    
        }
    
        subprojects {
            project.configurations.all {
                resolutionStrategy.eachDependency { details ->
                    if (details.requested.group == 'com.android.support'
                            && !details.requested.name.contains('multidex') ) {
                        details.useVersion "27.1.1"
                    }
    
                    if (details.requested.group == 'androidx.core'
                            && !details.requested.name.contains('androidx') ) {
                        //details.useVersion "1.0.1"
                   details.useVersion "1.5.0"
                    }
                }
            }
        }
    
    }
    
    allprojects {
        repositories {
            google()
            jcenter()
            mavenCentral()  // Maven Central repository
        }
    }
    
    rootProject.buildDir = '../build'
    subprojects {
        project.buildDir = "${rootProject.buildDir}/${project.name}"
    }
    subprojects {
        project.evaluationDependsOn(':app')
    }
    
    task clean(type: Delete) {
        delete rootProject.buildDir
    }
    
    
    

    And and my app/build.gradle dependencies is

    
    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'
    }
    
    apply plugin: 'com.android.application'
    apply plugin: 'kotlin-android'
    apply plugin: 'com.google.gms.google-services'
    apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
    
    android {
        compileSdkVersion 33
    
        sourceSets {
            main.java.srcDirs += 'src/main/kotlin'
        }
    
        lintOptions {
            disable 'InvalidPackage'
        }
    
        defaultConfig {
            // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
            applicationId "appname"
            minSdkVersion 20
            //noinspection OldTargetApi
            multiDexEnabled true
            targetSdkVersion 33
            versionCode flutterVersionCode.toInteger()
            versionName flutterVersionName
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        }
    
        buildTypes {
            release {
                // TODO: Add your own signing config for the release build.
                // Signing with the debug keys for now, so `flutter run --release` works.
                signingConfig signingConfigs.debug
            }
        }
    }
    
    flutter {
        source '../..'
    }
    
    
    
    dependencies {
        implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
        testImplementation 'junit:junit:4.12'
        implementation 'com.google.firebase:firebase-analytics'
        androidTestImplementation 'com.android.support.test:runner:1.0.2'
        androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
        implementation 'com.android.support:multidex:1.0.3'
        implementation platform('com.google.firebase:firebase-bom:31.0.2')
    
    }
    
    
    

    The above solved the issue for me.


  2. add build.repositories jcenter() and to allprojects.repositories jcenter(), in your build.gardle file

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