I tried to connect my flutter app with firebase and I catch up with this error

Viewed 856

I tried to connect my flutter app with firebase and I catch up with this error. Thanks in advance:)

FAILURE: Build failed with an exception.

  • What went wrong: A problem occurred configuring root project 'android'.

Could not resolve all artifacts for configuration ':classpath'. Could not resolve com.google.gms:google-services:4.3.8. Required by: project : > Could not resolve com.google.gms:google-services:4.3.8. > Could not get resource 'https://dl.google.com/dl/android/maven2/com/google/gms/google-services/4.3.8/google-services-4.3.8.pom'. > Could not GET 'https://dl.google.com/dl/android/maven2/com/google/gms/google-services/4.3.8/google-services-4.3.8.pom'. > Connect to 127.0.0.1:8080 [/127.0.0.1] failed: Connection refused: connect > Could not resolve com.google.gms:google-services:4.3.8. > Could not get resource 'https://jcenter.bintray.com/com/google/gms/google-services/4.3.8/google-services-4.3.8.pom'. > Could not GET 'https://jcenter.bintray.com/com/google/gms/google-services/4.3.8/google-services-4.3.8.pom'. > Connect to 127.0.0.1:8080 [/127.0.0.1] failed: Connection refused: connect

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

My app\build.gradle:

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 30

    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 "com.example.untitled2"
        minSdkVersion 16
        targetSdkVersion 30
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    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"
    implementation platform('com.google.firebase:firebase-bom:28.1.0')
}

My android\build.gradle:

buildscript {
    repositories {
        google()
        mavenCentral()
        jcenter()

    }

    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.0'
        classpath 'com.google.gms:google-services:4.3.8'
    }
}

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

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

task clean(type: Delete) {
    delete rootProject.buildDir
}

flutter doctor -v :

[√] Flutter (Channel stable, 2.0.5, on Microsoft Windows [Version 10.0.19042.1023], locale en-IN)
    • Flutter version 2.0.5 at C:\flutter
    • Framework revision adc687823a (8 weeks ago), 2021-04-16 09:40:20 -0700
    • Engine revision b09f014e96
    • Dart version 2.12.3

[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at C:\Users\Geo Swift Sam\AppData\Local\Android\sdk
    • Platform android-30, build-tools 30.0.3
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174)
    X Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/windows#android-setup for more details.

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

[√] Android Studio (version 4.1.0)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174)

[√] Connected device (3 available)
    • Android SDK built for x86 (mobile) • emulator-5554 • android-x86    • Android 10 (API 29) (emulator)
    • Chrome (web)                       • chrome        • web-javascript • Google Chrome 91.0.4472.101
    • Edge (web)                         • edge          • web-javascript • Microsoft Edge 90.0.818.66

! Doctor found issues in 1 category.
2 Answers

It may sound a silly answer, but this seems like an internet connection issue. I have faced similar issues during gradle sync on my mobile network while it worked fine in LAN.

In your android/build.gradle change the google-services version from 4.3.8 to 4.3.3 as stated in the documentation

classpath 'com.google.gms:google-services:4.3.3'

Give it a try and let me know.

Documentation reference: https://firebase.flutter.dev/docs/installation/android

Related