背景:

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


当前回答

当您在项目中下载的谷歌Services Json文件的包名称与项目的包名称不匹配时,会发生此错误。

最近重命名的项目包名称?

它会更新所有的类,但不会更新Gradle File。所以检查你的包名在Gradle中是否正确,Manifest也可以。

其他回答

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

这意味着你的谷歌服务。json文件不属于你的应用程序(你下载了谷歌服务吗?Json的另一个应用程序?)要解决这个问题,请执行以下步骤:

1:Sign in to Firebase and open your project. 2:Click the Settings icon and select Project settings. 3:In the Your apps card, select the package name of the app you need a config file for from the list. 4:Click google-services.json. After the download completes,add the new google-services.json to your project root folder,replacing the existing one..or just delete the old one. Its very normal to download the google-services.json for your first project and then assume or forget that this specific google-services.json is tailored for your current project alone,because not any other because all projects have a unique package name.

我来自react native,但我认为这也适用于这个问题。指定。

在文件android/app/build中。gradle搜索applicationId(在android中,defaultConfig)

确保这个值和这个一样

客户端[0]client_info.android_client_info.package_name

作为google-services.json中的值。

你需要放置google服务。Json到app/ dir。对于每一种构建类型,都应该有一致的主管 app / src文件夹。

例如,如果你有release和debug:

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

在谷歌的所有服务中。您应该根据构建类型指定正确的package_name。

例如,在调试目录中,它应该像{com.myapp}.debug

没有为包名称“com.tf”找到匹配的客户端 我很确定google-services中的“package_name”。json与你的“applicationId”在app gradle中不匹配。

应用gradle:

defaultConfig {
        applicationId "com.tf" //replace with the package_name in google-services.json =
        minSdkVersion 23
        targetSdkVersion 26
        versionCode 7
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

google-services.json

"client_info": {
        "mobilesdk_app_id": "1:23978655351:android:2b2fece6b961cc70",
        "android_client_info": {
          "package_name": "in.ac.geu.debug"
        }
      },

解决方案:确保package_name和applicationId必须相同。