简体   繁体   English

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

[英]Google Login without google-services.json file

I have been looking for a method in order to add the google-services.json at runtime as we use same base code to configure the application for the different client, hence we want to add google-services.json at runtime.我一直在寻找一种在运行时添加 google-services.json 的方法,因为我们使用相同的基本代码为不同的客户端配置应用程序,因此我们希望在运行时添加 google-services.json。

I have tried several links but am unable to find such a way to do it.我尝试了几个链接,但找不到这样的方法。

Any help will be very much appreciated.任何帮助将不胜感激。

The google-services.json is actually never read at runtime. google-services.json实际上永远不会在运行时读取。 During the build process of your Android app, the relevant information from google-services.json is translated into your App's XML resources, and that is where it's read when the app starts.在你的Android应用程序的构建过程中,从相关信息, google-services.json被翻译成你的应用程序的XML资源,而正是它的阅读应用程序启动时。 Since the destination where the build plugin puts the values is hard-wired, you can't configure it to have multiple sets of configuration data.由于构建插件放置值的目标是硬连接的,因此您无法将其配置为具有多组配置数据。

Instead of trying to read google-services.json at runtime, I'd recommend configuring the FirebaseApp instance in your code explicitly, like this:我建议不要在运行时尝试读取google-services.json ,而是建议在您的代码中显式配置FirebaseApp实例,如下所示:

// 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();

Now you can determine yourself where to keep the relevant information from the google-services.json and which ones to use when the app starts.现在,您可以自己决定将google-services.json的相关信息保存在何处,以及在应用程序启动时使用哪些信息。

and then:进而:

// 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);

Also see:另见:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何保存google-services.json文件 - How to save google-services.json file 删除或更改google-services.json文件 - Delete or change google-services.json file 没有 google-services.json 和 google play 服务的 Firebase crashlytics - Firebase crashlytics without google-services.json and google play services 错误:文件 google-services.json 丢失。 没有它,Google 服务插件就无法运行。 - Error: File google-services.json is missing. The Google Services Plugin cannot function without it. Flutter:文件 google-services.json 丢失。 没有它,Google 服务插件不能 function - Flutter : File google-services.json is missing. The Google Services Plugin cannot function without it 文件 google-services.json 丢失。 如果没有 ionic 3,Google 服务插件将无法运行 - File google-services.json is missing. The Google Services Plugin cannot function without it ionic 3 文件google-services.json丢失。 没有它,Google Services插件将无法运行 - File google-services.json is missing. The Google Services Plugin cannot function without it Android -File google-services.json丢失了。没有它,Google Services插件无法运行 - Android -File google-services.json is missing. The Google Services Plugin cannot function without it 文件 google-services.json 丢失。 没有它,Google 服务插件就无法运行。 搜索位置: - File google-services.json is missing. The Google Services Plugin cannot function without it. Searched Location: 找不到Google-services.json - Google-services.json not found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM