[英]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.