背景:

我试图为我的应用程序设置谷歌分析(有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.


当前回答

如果这些对你们中的一个都不起作用,我的问题是包名不是以“com”开头的。 改了,现在有用了。

希望这能有所帮助

其他回答

如果这些对你们中的一个都不起作用,我的问题是包名不是以“com”开头的。 改了,现在有用了。

希望这能有所帮助

去谷歌服务。json文件和在客户端部分检查包名称,并与App包名称进行比较,如果它们是不同的,然后根据您的App包名称更改客户端包名称,它为我工作,祝我好运。

谷歌服务。Json文件-> "package_name": "com.example.application.tracker"

应用程序包名称->包"com.example.application.tracker";

在应用程序的构建中检查applicationIdSuffix。gradle文件。查看它是否将任何文本连接到applicationId。如果是,请移除。

我也得到这个问题时,我改变包的名称我的应用程序。

在你的android studio项目中找到“google-services”。json文件。 打开它。 并检查应用程序的包名是否与此文件中所写的相同。

应用程序的包名和写在“google-services”中的包名。Json”文件必须相同。

确保在重命名包后重命名gradle文件中的ApplicationId