找不到与包名称匹配的客户端(Google Analytics(分析))-多个productFlavors和buildTypes [关闭]

本文翻译自:No matching client found for package name (Google Analytics) - multiple productFlavors & buildTypes [closed]

Context: 内容:

I'm trying to set up Google Analytics for my app. 我正在尝试为我的应用设置Google Analytics(分析)。 (having 4 custom buildTypes and more than a few productFlavors ) (具有4个自定义buildTypes和多个productFlavors

It works fine when I select the Build Variant which has the applicationId set to com.my.app.package.name (the package name used when generating the google-services.json ). 当我选择将applicationId设置为com.my.app.package.name (生成google-services.json时使用的包名称)的Build Variant时,它可以正常工作。 But, my other flavors have different applicationIds. 但是,我的其他口味具有不同的applicationIds。

I followed the offical devguide to set it up. 我按照官方的devguide进行了设置。

Error I get when any another build variant is selected in Build Variants Tab (which has a different applicationId (package name) is as follows: 在“ Build Variants Tab (具有不同的applicationId (包名称))中选择了任何其他构建变体时,出现以下错误:

Error:Execution failed for task ':app:processAllcategoriesDebugfreeGoogleServices'. 错误:任务':app:processAllcategoriesDebugfreeGoogleServices'的执行失败。

No matching client found for package name 'com.my.app.package.name.debug' 找不到与包名称'com.my.app.package.name.debug'匹配的客户端

Explanation of Error Message: 错误消息说明:

In the task name in the error message above Debugfree is my custom buildType and Allcategories is one of my productFlavors . 在错误消息上方的任务名称中, Debugfree是我的自定义buildTypeAllcategories是我的productFlavors

I understand the error and know the package name is different from what i used when generating the json, but that is what I'm trying to figure a way around. 我理解错误,并且知道包名称与生成json时使用的包名称不同,但这就是我试图解决的方法。

Problem: 问题:

Now, the google-services.json resides in the app folder and hence I am not being able to separate them out for each product flavor by dropping them in the flavor specific source set folder. 现在, google-services.json驻留在app文件夹中,因此我无法通过将它们放在特定于口味的源集文件夹中针对每种产品口味将它们分开。

Questions: 问题:

  1. My custom byildType for debugging suffixes .debug to the applicationId (package name). 我用于调试的自定义byildType.debug附加到applicationId (程序包名称)。 Is there a way I can make it work with the google-services.json which has my release applicationId (ie without the suffix .debug ) 有什么办法可以使它与具有我的发布applicationIdgoogle-services.json一起工作(即不带后缀.debug
  2. 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. 有没有一种方法可以在同一google-services.json文件中配置多种产品口味,而无需使用单独的文件和任务将所需文件复制到app文件夹。 I know it can be done using task as mentioned in this post . 我知道这是可以做到用task中提到的这篇文章 Is there a simpler way to just have one file or pick right file based on gradle configuration? 是否有更简单的方法来基于gradle配置仅拥有一个文件或选择正确的文件?
  3. I see the package_name field in google-services.json has the package name com.my.app.package.name . 我看到google-services.jsonpackage_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. 在文档中找不到任何说明。

#1楼

参考:https://stackoom.com/question/2MocZ/找不到与包名称匹配的客户端-Google-Analytics-分析-多个productFlavors和buildTypes-关闭


#2楼

Found this: 发现了这一点:

The google-services.json file is generally placed in the app/ directory, but as of version 2.0.0-alpha3 of the plugin support was added for build types , which would make the following directory structure valid: google-services.json文件通常放置在app /目录中, 但自版本2.0.0-alpha3起,已为构建类型添加了对插件的支持 ,这将使以下目录结构有效:

 app/src/ main/google-services.json dogfood/google-services.json mytype1/google-services.json ... 

Source 资源

Source 2 来源2


#3楼

check if client_id and package_name in the google-services.json has a correct value according to your package name. 根据您的软件包名称检查google-services.json中的client_idpackage_name是否具有正确的值。

You should add the mentioned file into the flavors directory with corresponding package name in the client_id and package_name field. 您应该在client_idpackage_name字段中使用相应的包名称将提到的文件添加到flavors目录中。


#4楼

Check your package name on your google-services.json it should be same with your local package name of your app google-services.json上检查您的软件包名称,该名称应与您的应用的本地软件包名称相同

Example

"client_info": {
    "mobilesdk_app_id": "1:6596814400689:android:65d6f25f5006145",
    "android_client_info": {
      "package_name": "com.my.app.package.name"
    }

In this case my local package name is com.my.app.package.name so also i have changed my package name in google-services.json with my local package name 在这种情况下,我的本地软件包名称是com.my.app.package.name,所以我也用本地软件包名称更改了google-services.json中的软件包名称


#5楼

You need to place google-services.json into app/ dir. 您需要将google-services.json放入app/目录中。 And for each build type, there should be accordant director in app/src folder. 对于每种构建类型, app/src文件夹中都应该有一致的Director。

For example, if you have release and debug: 例如,如果您具有发布和调试功能:

app/google-services.json
app/src/debug/google-services.json

In all google-services.json files you should specify correct package_name according to build type. 在所有google-services.json文件中,您应该根据构建类型指定正确的package_name

For example, inside debug dir it should be like {com.myapp}.debug 例如,在debug dir中,它应类似于{com.myapp}.debug


#6楼

I solved it by making two sourcesets , one free and one paid. 我通过制作两个资源集解决了这个问题,一个是免费的,一个是付费的。 Both of these folders will contain required java code and resource files, which will be edited to the requirements of the particular flavor. 这两个文件夹都将包含必需的Java代码和资源文件,将根据特定风味的要求对其进行编辑。 For example, You would like to remove AdMob Code in the Paid both from Java Classes and Layout Files. 例如,您想从Java类和布局文件中删除付费中的AdMob代码。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值