No matching client found for package name (Google

2019-01-03 13:15发布

Context:

I'm trying to set up Google Analytics for my app. (having 4 custom buildTypes and more than a few 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). But, my other flavors have different applicationIds.

I followed the offical devguide to set it up.

Error I get when any another build variant is selected in Build Variants Tab (which has a different applicationId (package name) is as follows:

Error:Execution failed for task ':app:processAllcategoriesDebugfreeGoogleServices'.

No matching client found for package name '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.

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.

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.

Questions:

  1. 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)
  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. 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?
  3. 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.

26条回答
地球回转人心会变
2楼-- · 2019-01-03 13:38

Make sure you rename ApplicationId in gradle file after rename your package

查看更多
别忘想泡老子
3楼-- · 2019-01-03 13:41

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. For example, You would like to remove AdMob Code in the Paid both from Java Classes and Layout Files.

查看更多
Luminary・发光体
4楼-- · 2019-01-03 13:41

It is simple to solve this: just make sure the package name in your app/build.gradle file is this same package name as the ones in your App Manifest file. and ensure the package name is correct. That should solve this

查看更多
淡お忘
5楼-- · 2019-01-03 13:42

You need to place google-services.json into app/ dir. And for each build type, there should be accordant director in app/src folder.

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.

For example, inside debug dir it should be like {com.myapp}.debug

查看更多
Juvenile、少年°
6楼-- · 2019-01-03 13:42

check if client_id and package_name in the google-services.json has a correct value according to your package name.

You should add the mentioned file into the flavors directory with corresponding package name in the client_id and package_name field.

查看更多
放我归山
7楼-- · 2019-01-03 13:43

if none of it worked for one of you guys, my problem was with a package name that didn't start with a 'com'. changed it, now it works.

hope that helps

查看更多
登录 后发表回答