'Android Studio's project gradle file changed?

I just updated Android Studio and started a new project. But now the project grade file seems different.

Here are the lines:

plugins {
    id 'com.android.application' version '7.1.0' apply false
    id 'com.android.library' version '7.1.0' apply false
}
 
task clean(type: Delete) {
    delete rootProject.buildDir
}

Now, for example, I need to paste the Firebase lines in the project level Gradle file. Where should I do it?

Here's the Firebase code:

buildscript {
  repositories {
    google()  // Google's Maven repository

  }
  dependencies {
    classpath 'com.google.gms:google-services:4.3.10'

  }
}

allprojects {
  repositories {
    google()  // Google's Maven repository

  }
}

In all of my previous projects, the Gradle structure was also like that. Now I'm a little confused about what to do.



Solution 1:[1]

But now the project grade file seems different.

Yes, starting with the new Bumblebee update of Android Studio, the build.gradle (Project) file is changed. In order to be able to use Google Services, you have to add into your build.gradle (Project) file the following lines:

plugins {
    id 'com.android.application' version '7.1.0' apply false
    id 'com.android.library' version '7.1.0' apply false
    id 'com.google.gms.google-services' version '4.3.0' apply false ?
}

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

And inside your build.gradle (Module) file, the following plugin IDs:

plugins {
    id 'com.android.application'
    id 'com.google.gms.google-services' ?
}

In this way, your Firebase services will finally work.

P.S. Not 100% sure if the Firebase Assistant is updated with these new Android Studio changes.

Edit:

There is nothing changed regarding the way you add dependencies in the build.gradle (Module) file. If for example, you want to add Firestore and Glide, please use:

dependencies {
    //Regular dependecies
    implementation platform("com.google.firebase:firebase-bom:29.0.4")
    implementation "com.google.firebase:firebase-firestore"
    implementation "com.github.bumptech.glide:glide:4.12.0"
}

Edit2:

With the new updates, you don't need to worry about adding any lines under the repositories { }. That was a requirement in the previous versions.

Solution 2:[2]

Alex Mamo's solution worked fine for firebase and glide libraries without needing to add any lines under the repositories { }.

But I was trying to add the following library and faced errors.

https://github.com/denzcoskun/ImageSlideshow

Something like this,

Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.github.denzcoskun:ImageSlideshow:0.1.0.
Show Details
Affected Modules: app

After doing some research I found out that you actually need to add lines under repositories { } in some cases. But after the new Android Studio update the gradle structure has changed. You will need to paste the required lines in the settings.gradle file instead of project level build.gradle file.

So in settings.gradle file, I added those lines like the following...

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        maven { url 'https://jitpack.io' }
    }
}

and the library started working fine.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Bucky