Google 没有 google-services.json 服务插件无法运行

Google Services Plugin cannot function without google-services.json

File google-services.json is missing. The Google Services Plugin cannot function

我收到此错误代码是因为我从我的项目中删除了我的 google-services.json 文件。现在解决这个问题的明显方法是再次包含它,但我有理由删除它。

"Note: If you enabled only Google Sign-In when you generated the configuration file, you can skip this step. Google Sign-In does not require the configuration file to be included in your project—generating the file performs the neecessary configuration steps." - 这是文档中的官方说明,因为 我只启用了 Google 登录 我没有看到此错误消息的原因。有没有人也遇到过这个问题并解决了它,因为我认为我正确地实现了所有内容。

注意:与包含的项目中的文件一起工作。

编辑: 澄清一下,我的应用程序运行良好,没有任何问题,但我想知道为什么我不能删除 google-services.json文件,即使我应该能够毫无问题地做到这一点!

您正在使用 Google 登录,对吗?所以你肯定需要一个 google-services.json 文件

参考这个 link

https://developers.google.com/identity/sign-in/android/start-integrating

将依赖项添加到您的项目级别 build.gradle:

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

将插件添加到您的应用级别 build.gradle:

apply plugin: 'com.google.gms.google-services'

类路径引用并应用的 gradle-plugin google-services 只是一个构建时插件!所以它只会影响你的应用程序的构建过程,而不是运行时过程! 这就是为什么您的应用运行良好但需要 google-服务 json 的原因。

当您在应用级别 build.gradle 中添加 apply plugin: 'com.google.gms.google-services' 时,它会从 google-services.json 文件中解析配置信息。

您删除了 google-services.json 文件,这就是它无法解析的原因
因此,也请从触发解析以使其工作的应用级别 build.gradle 中删除以下行再次.

apply plugin: 'com.google.gms.google-services'