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

AndroidAndroid StudioGradleGoogle AnalyticsAndroid Productflavors

Android Problem Overview


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.

Android Solutions


Solution 1 - Android

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

Solution 2 - Android

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

Solution 3 - Android

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.

Solution 4 - Android

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

Solution 5 - Android

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

Solution 6 - Android

> 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 ]

Solution 7 - Android

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.

Solution 8 - Android

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

Solution 9 - Android

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

Solution 10 - Android

1.Verify Package name and Application ID should be same

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

Solution 11 - Android

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.

Solution 12 - Android

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

Solution 13 - Android

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.

Solution 14 - Android

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.

Solution 15 - Android

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

Solution 16 - Android

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.

Solution 17 - Android

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

Solution 18 - Android

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

Solution 19 - Android

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 !

Solution 20 - Android

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

Solution 21 - Android

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

Solution 22 - Android

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

> Tools > Firebase > Connect to Firebase > Sync

Solution 23 - Android

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.

Solution 24 - Android

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";

Solution 25 - Android

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.

Solution 26 - Android

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 

Solution 27 - Android

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.

Solution 28 - Android

you can do that for sovling this problem.

enter image description here

Solution 29 - Android

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.

Solution 30 - Android

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

Solution 31 - Android

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

Solution 32 - Android

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.

Solution 33 - Android

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

Recommended Android Productflavors Solutions

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionViral PatelView Question on Stackoverflow
Solution 1 - AndroidMuhammed FasilView Answer on Stackoverflow
Solution 2 - AndroidViral PatelView Answer on Stackoverflow
Solution 3 - AndroidKailash KarkiView Answer on Stackoverflow
Solution 4 - AndroidUsmanView Answer on Stackoverflow
Solution 5 - Androidcahit beyazView Answer on Stackoverflow
Solution 6 - AndroidRavi VaniyaView Answer on Stackoverflow
Solution 7 - AndroiddevDeejayView Answer on Stackoverflow
Solution 8 - AndroidDroid ChrisView Answer on Stackoverflow
Solution 9 - AndroidBogdan UstyakView Answer on Stackoverflow
Solution 10 - AndroidJohn Ruban SinghView Answer on Stackoverflow
Solution 11 - AndroidShayan AmaniView Answer on Stackoverflow
Solution 12 - AndroidSyed Arsalan ShahView Answer on Stackoverflow
Solution 13 - AndroidMichal Zhradnk Nono3551View Answer on Stackoverflow
Solution 14 - AndroidDAVIS BENNY 15MIS0426View Answer on Stackoverflow
Solution 15 - AndroidPapelView Answer on Stackoverflow
Solution 16 - AndroidThomasReggiView Answer on Stackoverflow
Solution 17 - AndroidSyed Hussain MehdiView Answer on Stackoverflow
Solution 18 - AndroidDulal KiskuView Answer on Stackoverflow
Solution 19 - AndroidAshok Kumar K RView Answer on Stackoverflow
Solution 20 - AndroideiranView Answer on Stackoverflow
Solution 21 - AndroidBayar ŞahintekinView Answer on Stackoverflow
Solution 22 - AndroidNabin BhandariView Answer on Stackoverflow
Solution 23 - AndroidOsman YalınView Answer on Stackoverflow
Solution 24 - AndroidShah RukhView Answer on Stackoverflow
Solution 25 - AndroidAbhiroj PanwarView Answer on Stackoverflow
Solution 26 - AndroidChaudhary NoumanView Answer on Stackoverflow
Solution 27 - Androidmehmoodnisar125View Answer on Stackoverflow
Solution 28 - Android指尖上的AndroidView Answer on Stackoverflow
Solution 29 - AndroidRileyMandaView Answer on Stackoverflow
Solution 30 - AndroidSyed Arsalan KazmiView Answer on Stackoverflow
Solution 31 - AndroidMohsentsView Answer on Stackoverflow
Solution 32 - AndroidPrakash PalanisamyView Answer on Stackoverflow
Solution 33 - AndroidJames IdowuView Answer on Stackoverflow