Firebase Integration in Android Studio

This is root level gradel -

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

    dependencies {
        classpath 'com.android.tools.build:gradle:7.3.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

plugins {
    id("com.google.gms.google-services") version "4.3.15"
}

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
}

This is app level gradel -

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 from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    namespace "com.example.brew_crew"
    compileSdkVersion flutter.compileSdkVersion
    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 "com.pratham.brew_crew"
        // You can update the following values to match your application needs.
        // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
        minSdkVersion flutter.minSdkVersion
        targetSdkVersion flutter.targetSdkVersion
        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 '../..'
}

plugins {
    id("com.android.application")
    id("com.google.gms.google-services")
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation(platform("com.google.firebase:firebase-bom:32.1.1"))
}

And i got this error after running. Somebody please explain the fix i’ve been stuck here for hours. (I tried everything ChatGPT suggested hence this is my last resort !)

Launching lib\main.dart on sdk gphone x86 in debug mode...
Running Gradle task 'assembleDebug'...

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\Users\NH1950\StudioProjects\brew_crew\android\build.gradle' line: 15

* What went wrong:
Plugin [id: 'com.google.gms.google-services', version: '4.3.15'] was not found in any of the following sources:

- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'com.google.gms.google-services:com.google.gms.google-services.gradle.plugin:4.3.15')
  Searched in the following repositories:
    Gradle Central Plugin Repository

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

I tried everything ChatGPT suggested hence this is my last resort

Why is this the “last resort”?
You didn’t try any helpful resource yet.
ChatGPT is not good at giving correct answers.
I is just good at giving answers that look correct, but often he made up the most things.

Besides that its database is more than 2 years old, which is ages in computer time,
ChatGPT is only good for things you could do yourself but are too lazy. (The good kind of lazy, not the bad one).
You always have to understand what it did, and fix the non-sense it produces like calling methods on APIs that never existed and so on.

ChatGPT answers are also not banned for nothing from sites like StackOverflow.

Regarding your problem, the error is quite meaningful.
It tells you that you tried to apply a plugin that it cannot find in the configured plugin repositories which is only the default, the Gradle Plugin Portal, where this plugin is not present.

Add

pluginManagement {
    repositories {
        gradlePluginPortal()
        google()
    }
}

to your settings script and the plugin will be found.

well i don’t know if this helped OP but i had my pluginManagment just like that and it’s still not working… so i turn it off and on again hopeing it would help, the problem was still there obviously but now there was a suggestion to " turn off offline mode " wich i didn’t know i had turned on in the first place, accept the helping hand and next thing my problem was no more… i don’t have a well based understanding of the why’s this worked but if someone else has this problem maybe this is your solution, hope it helps at least someone. Good luck y’ll !!!

But when you had it like I showed and got the error, you probably got both repositories listed, the Gradle Plugin Portal, and the Google repository. In that case, it could indeed be the offline mode. But for OP it showed only the GPP, so Google was definitely missing in the configuration. :slight_smile: