背景:

我试图为我的应用程序设置谷歌分析(有4个自定义buildTypes和多个productFlavors)

当我选择有applicationId设置为com.my.app.package.name(生成google-services.json时使用的包名)的Build Variant时,它工作得很好。但是,我的其他口味有不同的应用id。

我按照官方的开发指南来设置它。

当在build variables选项卡中选择任何其他构建变量时(具有不同的applicationId(包名)),我得到的错误如下:

错误:任务执行失败 “应用程序:processAllcategoriesDebugfreeGoogleServices”。 没有为包名'com.my.app.package.name.debug'找到匹配的客户端

错误信息解释:

在上面错误消息中的任务名称中,Debugfree是我的自定义buildType, Allcategories是我的productFlavors之一。

我理解这个错误,知道包的名称与我在生成json时使用的不同,但这就是我试图解决的问题。

问题:

现在,谷歌的服务。json驻留在app文件夹中,因此我无法通过将它们放入特定于风味的源集文件夹中将它们分离出来。

问题:

My custom byildType for debugging suffixes .debug to the applicationId (package name). Is there a way I can make it work with the google-services.json which has my release applicationId (i.e. without the suffix .debug) Is there a way to have multiple product flavors configured in the same google-services.json file without using separate files and tasks to copy the required file to app folder. I know it can be done using task as mentioned in this post. Is there a simpler way to just have one file or pick right file based on gradle configuration? I see the package_name field in google-services.json has the package name com.my.app.package.name. Can I add multiple package names manually to work for all build variants? If yes, how to do that? Could not find any instructions in documentations.


当前回答

发现了这个:

谷歌服务。Json文件一般放置在app/ 目录,但作为版本2.0.0-alpha3的插件支持 为构建类型添加,这将创建以下目录 结构有效: 应用程序/ src / 主要/ google-services.json 下dogfood / google-services.json mytype1 / google-services.json ...

源2

其他回答

我找到了解决方案:

我们必须在firebase项目中创建两个“应用程序”,然后我们可以从任何一个应用程序下载json文件(我从调味应用程序下载)。它将包含两个应用程序的数据。我们可以简单地将json文件复制到应用程序的根目录。

来源:https://firebase.googleblog.com/2016/08/organizing-your-firebase-enabled-android-app-builds.html

确保您的包名称在“google-services”中。Json”文件与应用程序的包名称相同。

我认为你已经添加了firebase json文件“google-services”。Json和新文件。确保创建一个新文件,检查如何从firebase创建json文件的链接,它应该与你的包名匹配

第二件事是,如果你要改变包的名称,当你从下拉菜单中选择项目时,右键单击文件下的“替换路径”选项。你必须在整个项目中搜索包名并替换它!

希望这能有所帮助!

我通过制作两个资源集来解决这个问题,一个是免费的,一个是付费的。这两个文件夹都将包含所需的java代码和资源文件,这些文件将根据特定类型的要求进行编辑。例如,你想从Java类和布局文件中删除付费的AdMob代码。

无论何时创建或更新包名,请确保包名完全相同[大写和小写都很重要]

执行下面的步骤。

1).检查应用程序级别gradle文件中的applicationId,

2).在google-services中检查package_name。json文件,

3).检查AndroidManifest文件中的package

为了完全确认,请确保您的工作包目录名称(“com.example.app”)也是相同的。

编辑[任何在productFlavour场景中面临这个问题的人,去看看Droid Chris的解决方案]