firebase - 没有 google-services.json 文件的 Google 登录

标签 firebase google-signin google-plugin-eclipse google-play-services

我一直在寻找一种方法来在运行时添加 google-services.json,因为我们使用相同的基本代码为不同的客户端配置应用程序,因此我们希望在运行时添加 google-services.json。

我尝试了几个链接,但找不到这样的方法。

任何帮助将不胜感激。

最佳答案

google-services.json 实际上在运行时永远不会被读取。在 Android 应用的构建过程中,google-services.json 中的相关信息会转换为应用的 XML 资源,并且是应用启动时读取的位置。由于构建插件放置值的目的地是硬连线的,因此您无法将其配置为具有多组配置数据。

我建议您在代码中显式配置 FirebaseApp 实例,而不是尝试在运行时读取 google-services.json,如下所示:

// Manually configure Firebase Options
FirebaseOptions options = new FirebaseOptions.Builder()
        .setApplicationId("1:27992087142:android:ce3b6448250083d1") // Required for Analytics.
        .setApiKey("AIzaSyADUe90ULnQDuGShD9W23RDP0xmeDc6Mvw") // Required for Auth.
        .setDatabaseUrl("https://myproject.firebaseio.com") // Required for RTDB.
        .build();

现在,您可以自行决定将 google-services.json 中的相关信息保存在何处,以及在应用启动时使用哪些信息。

然后:

// Initialize with secondary app.
FirebaseApp.initializeApp(this /* Context */, options, "secondary");

// Retrieve secondary app.
FirebaseApp secondary = FirebaseApp.getInstance("secondary");
// Get the database for the other app.
FirebaseDatabase secondaryDatabase = FirebaseDatabase.getInstance(secondary);

另请参阅:

关于firebase - 没有 google-services.json 文件的 Google 登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48947543/

相关文章:

ios - GoogleSignIn/Crashlytics/Firebase 的自定义编译器标志

firebase - 带有 Firebase Auth 的 Flutter Web 无法在本地工作,但在部署在云中时可以工作

android - 默认 "appengine connected Android project"500 错误

java - 项目无法在 Google Cloud Tools for Eclipse 上启动

ios - Firebase 快速作为 OS X 的后端服务

firebase - 为什么我无法通过Firebase Cloud函数将文档插入到我的Elasticsearch索引中?

android - 从 GoogleSignInOptions Android 请求电子邮件时发生 INTERNAL_ERROR

google-app-engine - 尝试部署 GAE App 时出现 "Unable to update app: Failed to compile the generated JSP java files."

java - 如何在Firebase中获取 child 的数据

firebase - Flutter Firebase 实时 once().then() 重新运行时不会更新