如何使用同一个google-services.json文件使多个应用程序版本相同? [英] How can I make multiple app flavors use the same google-services.json file?

查看:248
本文介绍了如何使用同一个google-services.json文件使多个应用程序版本相同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想拥有一个带有一个应用程序ID的google-services.json文件,该文件连接到一个Firebase项目"中的一个Firebase应用程序",供我的Android应用程序的各种版本使用.

我的口味具有不同的品牌,但它们的工作原理几乎相同,我希望所有这些口味的分析数据都可以存储在Firebase中的同一位置.但是,它们(当然)都具有不同的后缀Android应用程序ID/程序包名称,并且这些风味程序包名称都与google-services.json中的名称完全匹配,而后者根本没有后缀.

我已经看到了许多方法,可以在同一个Firebase项目"中将Android应用程序的不同版本连接到不同的Firebase应用程序",但这不是我想要做的:我想将不同Android应用程序版本连接到相同 Firebase应用".

是否可以使用Firebase进行此操作,还是应该在其他地方查看?

谢谢, 丹·维比(Dan Wiebe)

解决方案

实际上,我以前的回答不足以回答您的问题,因此我创建了逐步指南.

一步一步

  1. 使用您想要的默认产品样式构​​建应用程序.

  2. app/build.gradle中删除apply plugin: 'com.google.gms.google-services.此插件读取google-services.json中的值,并在编译时将其复制到xml值文件中.我们将在第4步中手动执行此操作.

  3. 在主文件夹中创建一个新的(或使用现有的)xml值文件.

  4. 转到app/build/generated/res/google-services/{productFlavor}/debug/values/values.xml并将这些值复制到在步骤3中创建的xml值中.将{productFlavor}替换为在步骤1中选择的产品风味.

  5. 删除google-services.json

现在将使用默认应用程序中的凭据,您无需初始化我在上一个答案中提到的方式

I would like to have one google-services.json file, with one application ID, connected to one Firebase "app" in one Firebase "project," used by a variety of flavors of my Android app.

My flavors are branded differently, but they work very much the same, and I want the analytics data from all of them to end up in the same place in Firebase. However, they all (of course) have Android application IDs/package names that are suffixed differently, and none of those flavor package names match the one in the google-services.json, which doesn't have a suffix at all.

I've seen many ways to connect different flavors of an Android app to different Firebase "apps" in the same Firebase "project," but that's not what I want to do: I want to connect different Android app flavors to the same Firebase "app."

Is there a way to do this with Firebase, or should I look elsewhere?

Thanks, Dan Wiebe

解决方案

Indeed my previous answer was not enough to answer your question so I've created an step by step guide.

Step by Step

  1. Build the application with the product flavor you want as default.

  2. Remove the apply plugin: 'com.google.gms.google-services from your app/build.gradle. This plugin reads the values in google-services.json and copies them on compile time in an xml values file. We will do this manually in step 4.

  3. Create a new (or use an existing) xml values file in the main folder.

  4. Go to app/build/generated/res/google-services/{productFlavor}/debug/values/values.xml and copy those values into the values xml created in Step 3. Replace {productFlavor} with the product flavor selected into Step 1.

  5. Delete the google-services.json

Now the credentials from your default application will be used and you don't need to initialise the way I mentioned in my previous answer

这篇关于如何使用同一个google-services.json文件使多个应用程序版本相同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆