Search code examples
androidfirebasegradlegoogle-cloud-platformgoogle-play-services

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

  • 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 to 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 2022-14-07:

    Here is a repo that uses this new structure:

    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.