No matching client found for package name (Google Analytics) - multiple productFlavors & buildTypes
Asked Answered
S

35

650

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.
Subordinate answered 25/1, 2016 at 10:37 Comment(5)
Did you find a soution especially for your third question?Antalya
I'm in similar situations. I need analytics support for one of prod-release flavour version only. I could able to limit added dependency to prod-flavour but it still search for right package as part of son file. Any suggestion !Inventory
I am also facing the same issue, Let me know if anyone finds the solution for this?Striated
in my case, i just changed the package nameFreudberg
if your using firebase in app then add your new applicationId as sub app(add app) issue will fixZenobiazeolite
S
318

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:

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

Source

Source 2

Subordinate answered 25/1, 2016 at 11:2 Comment(4)
Is there any way to disable analytics easily for a build type? I want to disable it for Debug? I thought it would be disabled if I don't add google-services file, but even if I disable, it still asks for google-services file.Garret
What would the difference each of the josn file added in each flavour??Fighter
Is there a possibility to use google services inside a module (that two apps share)... cause i can't even gradle-sync without having a google service file for that package... the embedding app should provide the json, but not the module. is this anyhow possible?Copalite
When I moved google-service.json to new folder named staging I got this error: File google-services.json is missing. The Google Services Plugin cannot function without it. . I need firebase only for staging, still - this doesn't solve the problem :(Accipitrine
G
701

Check your package name on your google-services.json it should be same with your local package name of your app

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

Greeneyed answered 5/7, 2016 at 7:51 Comment(5)
google-services.json is a file!!! within a app directory. Should find this file with the help of the Windows Explorer (for example). Should edit this file by the usual editor.Weld
to find this go to Project view in Android Studio and search inside your app packageCowherb
No... we all know google-services.json is invalid in this issue... What we want is how to solve this issue in build variant situation!!Hitormiss
If your activity is in a subpackage such as: com.example.aaron.myproject22.Activities.... you need to go into the google-services.json and change the client_info's package_name to com.example.aaron.myproject22 Also make sure you have apply plugin:'com.google.gms.google-services' at the bottom of build.grade (Module app)Lavellelaven
This fixed it for me. I'm using Firebase push notifications inside a library, and the google-services.json file that the Firebase Console generated used the app's package name instead of the library's package name. Thanks!Monody
S
318

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:

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

Source

Source 2

Subordinate answered 25/1, 2016 at 11:2 Comment(4)
Is there any way to disable analytics easily for a build type? I want to disable it for Debug? I thought it would be disabled if I don't add google-services file, but even if I disable, it still asks for google-services file.Garret
What would the difference each of the josn file added in each flavour??Fighter
Is there a possibility to use google services inside a module (that two apps share)... cause i can't even gradle-sync without having a google service file for that package... the embedding app should provide the json, but not the module. is this anyhow possible?Copalite
When I moved google-service.json to new folder named staging I got this error: File google-services.json is missing. The Google Services Plugin cannot function without it. . I need firebase only for staging, still - this doesn't solve the problem :(Accipitrine
R
181

No matching client found for package name 'com.tf' I am pretty sure that the "package_name" in google-services.json is not matching with your "applicationId" in app gradle.

app 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"
        }
      },

Solution: Just make sure the package_name and applicationId must be same.

Rhodesia answered 25/9, 2018 at 14:18 Comment(4)
Author was asking about a workaround to this. They have different build types with different applicationIdIconoscope
you have given to most valid solution. Kudos man !!Antho
The application id in app gradle nailed itYeh
This is the correct answer. Just make sure the package_name = applicationId. In my case, I was created a new project with a new name (A) and copy the old code from old project named (B). In project B the package_name is the name I chose on firebase console, but it is not matter, we do not need to match the name we have set on the SDK installation instruction.Corneliacornelian
M
91

I have found the solution:

We have to create two "apps" in the firebase project, and then we can download json file from any one app (I downloaded from the flavoured app). It will contain the data for both the apps. We can simply copy the json file to the app's root directory.

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

Maureenmaureene answered 27/12, 2016 at 10:58 Comment(5)
This is the best answer as all the product flavours can be covered by one json file. No need to create other sourcesets.Supporting
Please note, you have to create the apps inside the same project. Project Overview on the upper left corner has a settings icon. Press it and it will open to the General tab, scroll down and under Your Apps section there is a button Add AppReseta
The biggest problem will happen when you forget to change your google-service.json and push it to prod.Faery
@Reseta Creating two apps in the same project will require a different package ID. How to handle it?Loosejointed
@usman Creating two apps in the same project will require a different package ID. How to handle it?Loosejointed
B
84

Whenever you create or update package name Make sure your package name is exactly the same [Upper case and lower case matters]

Do below step.

1). Check applicationId in App level gradle file,

2). Check package_name in your google-services.json file,

3). Check package in your AndroidManifest file

and for full confirmation make sure that your working package directory name i.e.("com.example.app") is also the same.

EDIT [ Any one who is facing this issue in productFlavour scenario, go check out Droid Chris's Solution ]

Betseybetsy answered 18/6, 2018 at 9:40 Comment(4)
Thanks Bro it worked for me .In app level gradle file my package was different .When I changed it worked for meFabi
wel come @FabiBetseybetsy
You don't have to change package in manifest (and all files in all packages), as applicationId will change app id.Nashua
This is not what the author was asking aboutAccipitrine
A
78

make sure your package name in "google-services.json" file is same with your apps's package name.

Antiphonary answered 21/1, 2017 at 13:40 Comment(2)
common issue when forking a repo for a new project.Stenotypy
yes if both package name are not same than it is not workingOxygenate
L
66

First off, add a suffix to the application package in Gradle:

yourFlavor {
   applicationIdSuffix "yourFlavor"
}

This will cause your package to be named

com.domain.yourapp.yourFlavor

Then go to Firebase under your current project and add another android app to it with this package name.

Then replace the existing google-services.json file with the new one you generate with the new app in it.

Then you will end up with something that has multiple "client_info" sections. So you should end up with something like this:

"client_info": {
    "mobilesdk_app_id": "YOUR APP INFO",
    "android_client_info": {
      "package_name": "com.domain.yourapp"
    }
  }

"client_info": {
    "mobilesdk_app_id": "YOUR APP INFO - will be different then other app info",
    "android_client_info": {
      "package_name": "com.domain.yourapp.yourFlavor"
    }
  }
Lucienlucienne answered 17/7, 2018 at 20:45 Comment(11)
This is the right answer! You need both Apps (ids) in the google-services.json file.Turnspit
this is the way. +1, here's some old discussion that relates to this issuePudendas
Simple and straight forward.Adriaadriaens
This should be marked as correct answer regarding build variantsMimir
even tho I have answered to this question here [https://mcmap.net/q/63835/-no-matching-client-found-for-package-name-google-analytics-multiple-productflavors-amp-buildtypes], but for the productFlavour scenario, this is the best solution, I will sure link your answer in mine to help future devs, thx +1Betseybetsy
Correct answer !! Worked ,ThanksJulienne
this did not work for meDoehne
@AnnaHarrison post your code and see what your issue is. It seems now that Firebase automatically does what I had posted here.Lucienlucienne
@DroidChris Is there a way to do it through the build script, rather than manually appending each product flavor's entry at the google-services.json file? I can't even tell what the value of the mobilesdk_app_id property.Castigate
You should add all your project ids in the google-services.json like I put in the post. Then when you used build variants, in gradle, make the product id different between builds.Lucienlucienne
@polendina if you are still having issues feel free to reach out and we can fixLucienlucienne
L
59

This error occurs when you have a Google Services Json file downloaded in your project whose Package name doesn't match with your Project's package name.

Recently renamed the project's package name?

It does update all the classes but not the Gradle File. So check if your package name is correct in your Gradle, and also maybe Manifest too.

Lahey answered 29/4, 2019 at 5:35 Comment(0)
L
46

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

Laminitis answered 3/9, 2016 at 10:38 Comment(1)
Apparently you can even just duplicate the main set's element in the "client"'s array (add a comma between the elements) and change just the "package_name"'s value of the new element to include the .debug suffix. Then rebuild. It worked for me on AS 2.3.3.Naturally
M
32

1.Verify Package name and Application ID should be same

2.Verify google-services.json package name which is available in app folder

Macaluso answered 27/2, 2019 at 7:5 Comment(1)
I had to Invalidate Caches / Restart... as well to get this working.Judicative
T
26

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.

Tufts answered 30/5, 2016 at 17:21 Comment(0)
A
21

In my case I forgot google-services.json in app root directory which was for different flavour. It was used by default instead of using json stored in flavour's folder. This messed up plugin and since package names were not matching it failed.

Wisdom I taught, check for all google-services.json in your project structure when this problem occurs.

Adlare answered 8/12, 2020 at 14:25 Comment(0)
U
21

If anyone change their existing package name then sometimes it makes problem like that, so you should change local package name, build.gradle file package name and if your project have any google-services.json file then simply you need to change your JSON file package name too.

Old File look like that

"client": [
{
  "client_info": {
    "mobilesdk_app_id": "1:517104510151:android:8b7ed3989db24a6f928ae2",
    "android_client_info": {
      "package_name": "com.techsajib.oldapp"
    }
  },

New File look like that

"client": [
{
  "client_info": {
    "mobilesdk_app_id": "1:517104510151:android:8b7ed3989db24a6f928ae2",
    "android_client_info": {
      "package_name": "com.techsajib.newapp"
    }
  },

Note: sometimes JSON file have several package name so change all of them

Unholy answered 18/1, 2021 at 16:48 Comment(0)
P
20

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

Pederast answered 21/12, 2016 at 5:2 Comment(3)
Saved me. Thanks.Waterresistant
glad it helped someonePederast
Solved my problem too!Cott
B
17

Open your Google-services.json file and look for this section in the file:

"client": [
{
  "client_info": {
    "mobilesdk_app_id": "1:857242555489:android:46d8562d82407b11",
    "android_client_info": {
      "package_name": "com.example.duke_davis.project"
    }
  }

check whether the package is the same as your package name. Mine was different, so I changed it and it worked.

Bork answered 3/3, 2017 at 4:4 Comment(1)
Worked :) ThanksYonita
Z
13

Only two easy step to change package name:

  1. Open "build.gradle" file enter image description here

  2. Then add your new package name in "applicationId", now then click on "sync now" the project.

enter image description here

Note: If your "google-services.json" file is added in project then change your name package name there inside "client_info"

enter image description here

package name inside "google-services.json"

enter image description here

That's all. No need to change package name anywhere else.

Zeus answered 11/1, 2023 at 12:46 Comment(0)
S
11

Im coming from react native but I think that this applies to this question as well. To specify.

Within the file android/app/build.gradle search for applicationId (within android, defaultConfig)

and ensure that that value is the same this

client[0]client_info.android_client_info.package_name

as the value within google-services.json.

Suckerfish answered 1/8, 2017 at 18:16 Comment(0)
I
10

You also need to change package name in google-services.json

Insubstantial answered 1/5, 2018 at 8:17 Comment(0)
B
8

If your package name on Google-services.json file is okay, Go to gradle.properties file. Then change your APPLICATION_ID="com.yourpackage.name"

Bein answered 12/3, 2017 at 4:9 Comment(0)
O
6

I think you have added firebase json file "google-services".json with the new file. Make sure to create a new file check the link on how to create json file from firebase and it should match with your package name

Second thing is that if you are changing the package name use the option " replace in path" when you right click under files when you select project from the drop down. You have to search for package name in the whole project and replace it !

Hope this helps !

Owades answered 17/3, 2018 at 12:7 Comment(0)
S
4

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

Sealskin answered 4/4, 2017 at 15:50 Comment(0)
O
3

go your project directory and create folders on app/src path that named your product flavors (like Alpha, Beta, Store or what ever your flavor's name is). then copy your google-services.json file to each folder. don't forget to change "package_name" field on your each product flavor's google-services.json file that you subfoldered.

Oona answered 25/1, 2016 at 10:37 Comment(0)
J
3

I solved the same problem by re-syncing the file google-services.json.

Tools > Firebase > Connect to Firebase > Sync

Joaquin answered 9/10, 2017 at 11:42 Comment(2)
where did you do that? what does it replace exactly? Screenshot?Keifer
You can do that in Android Studio (Firebase plugin must be enabled). It updates the file google-services.json.Joaquin
B
3

Go to google-services.json file and in client part check the package name and compare it with App package name if they are different then change the client package name according to your app package name it worked for me best of luck..

google-services.json file-> "package_name": "com.example.application.tracker"

App package name->package "com.example.application.tracker";

Bowler answered 17/3, 2018 at 8:33 Comment(0)
P
3
android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.package.name"
        minSdkVersion 19
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

make sure Gradle.app's applicationId is same your package name. my problem was this and I solved this way

Placida answered 2/7, 2018 at 13:48 Comment(0)
A
2

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.

Action answered 13/11, 2016 at 10:48 Comment(0)
U
2

I solved the same problem here is simple solution: when you create firebase connection follow these guidelines:

  • Add your application name in firebase

  • Add your application pakage name (write same pakage name ,you are using in app)

  • when firebase make google-services.json file just download it and paste it in your app folder

  • Sync your project Problem is solved :)

    Thank you

Underfur answered 1/12, 2017 at 12:1 Comment(0)
R
2

I also get this issue when i change package name of my application.

In your android studio project find "google-services.json" file. Open it. and check whether package name of your application is same as written in this file.

The package name of your application and package name written in "google-services.json" file must be same.

Ruhr answered 13/6, 2018 at 4:37 Comment(0)
T
2

you can do that for sovling this problem.

enter image description here

Tungstic answered 21/5, 2019 at 9:37 Comment(3)
This will mask the problem instead of solving it. See other answers for a solution.Tympanist
Please use code instead of a screenshot, your answer is good in my case because I only want to create a "mockup" of an application clone.Pasturage
Sharing the code rather than screenshot would have been more useful.Pneumodynamics
C
1

This means your google-services.json file either does not belong to your application(Did you download the google-services.json for another app?)...so to solve this do the following:

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.

Chellman answered 24/1, 2018 at 20:16 Comment(0)
A
1

Check for applicationIdSuffix in your app's build.gradle file. See if it is concatenating any text to your applicationId. If so, remove it.

Augustus answered 20/1, 2019 at 13:33 Comment(0)
A
1

If your applicationId is different between your buildTypes, you can add those particular artifacts to specific dependency flavor like releaseImplementation for example.

Awakening answered 20/5, 2022 at 15:45 Comment(0)
T
1

I forgot to add SHA certificate fingerprint in Firebase. I just re-imported google-services.json and it worked

Tarshatarshish answered 20/9, 2022 at 8:45 Comment(0)
G
-1

Just simple. Sign-out from Android Studio, close it completely. Reopen Android studio and then again Sign-In to Android Studio.

Then try to connect to firebase from the Android studio IDE. This procedure worked for me.

Georgeannageorgeanne answered 16/5, 2018 at 12:4 Comment(2)
this is not working if google-services.json exists. we must delete google-services.json if it exists.Oleum
this will work once after you change the package name in the json file as well and before save that, you need to close the android studio and then save the json file and restart the studio.Fortnight
C
-3

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

Cobaltous answered 16/7, 2018 at 20:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.