在库中使用外部 google-services.json 文件

Use external google-services.json file in library

我在我的应用程序中共享一个登录模块,其中 LoginActivity 处理 Facebook 和 Google 身份验证(逻辑 + UI)。
现在,使用 Facebook 可以很容易地为每个应用程序指定不同的 ID,覆盖应用程序模块中库的 facebook_app_id 字符串。

我找不到对 Google 登录执行相同操作的方法,因为它需要 google-services.json 文件。事实上,如果我将文件包含在应用程序模块中而不是登录库中,构建就会失败。

Error:Execution failed for task ':core:processReleaseGoogleServices'.
File google-services.json is missing. The Google Services Plugin cannot function without it.

错误是不言自明的,我需要 google-services.json在登录模块中。关键是其他应用程序也有自己的 google-services.json

有没有办法在登录模块中添加一个虚拟 google-services.json,然后在每个应用程序中用真实的覆盖它?

库中不能有 google-services.json 文件。 你必须添加需要的依赖,编译成库就可以了。

而不是在将使用该库的项目中,您必须添加插件和 google-services.json 文件。

要在您的图书馆中执行此操作,在 build.gradle 必须删除

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