在项目 build.gradle 文件中的 dependencies 中寻找 classpath 'com.android.tools.build:gradle:x.x.x' 这一行,将 x.x.x 的版本号从旧版本更新到最新版。
buildscript {
   ...
   dependencies {
       classpath 'com.android.tools.build:gradle:4.2.0'
       ...
   }
}
修改 Gradle 版本,在 app 的 build.gradle 文件中将 gradle 的版本更新到最新版。
buildscript {
  ...
  dependencies {
      ...
      classpath 'com.google.gms:google-services:4.3.8'
  }
}
apply plugin: 'com.android.application'
android {
  ...
  compileSdkVersion 30
  buildToolsVersion "30.0.3"
  defaultConfig {
      ...
      minSdkVersion 21
      targetSdkVersion 30
      ...
  }
  ...
}
dependencies {
  implementation fileTree(dir: 'libs', include: ['*.jar'])
  implementation 'androidx.appcompat:appcompat:1.3.0'
  implementation 'com.google.android.material:material:1.3.0'
  implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
  // 添加以下代码段
  implementation 'com.google.firebase:firebase-analytics:19.0.0'
  implementation 'com.google.firebase:firebase-messaging:21.0.0'
  implementation 'com.google.firebase:firebase-crashlytics:17.3.0'
  implementation 'com.google.firebase:firebase-auth:21.0.1'
  implementation 'com.google.android.gms:play-services-auth:19.0.0'
}
// 添加以下代码段
apply plugin: 'com.google.gms.google-services'
同步 Gradle。在 Android Studio 右上角点击 Sync Now 即可同步 Gradle。
完成以上三步之后,重新运行应用,问题应该就能够得到解决。