'No matching client found for package name "...." with different buildvariant

I want o implement push notification. I added to project level:

dependencies {
        classpath 'com.android.tools.build:gradle:2.2.2'
        classpath 'com.google.gms:google-services:3.0.0'
}

and to app level:(at the bottom of the file)

   ....
   compile 'com.squareup.okhttp3:okhttp:3.3.0'
}
apply plugin: 'com.google.gms.google-services'

Then I added google-services.json file to project in app level

But, when I syncro gradle, it launch the error:

No matching client found for package name "...." 

In gradle I have 2 different build variants , and look like:

enter image description here

Manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="es.xxx.awsomeapp">

    <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:name=".realm.XXXXXX"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher_chv"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity

And finally the gradle:

apply plugin: 'com.android.application'
apply plugin: 'realm-android'

repositories {
    maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
    maven { url "https://s3.amazonaws.com/repo.commonsware.com" }
    maven { url "https://jitpack.io" }
    maven { url 'http://dl.bintray.com/amulyakhare/maven' }
    mavenCentral()
}
android {
    compileSdkVersion 24
    buildToolsVersion "24.0.2"
    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    productFlavors {
        vanilla {
            applicationId "es.xxx.awsomeApp"
            resValue 'string', 'app_name', "Awsome"
        }
        chv {
            applicationId "es.xxx.awsomeApp.chv"
            resValue 'string', 'app_name', "Awsome CHV"
            signingConfig signingConfigs.chv_release
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    testOptions {
        unitTests.returnDefaultValues = true
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    //Auxiliar libraries
    compile 'org.igniterealtime.smack:smack-android-extensions:4.2.0-beta2'
    //Auxiliar libraries
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'org.igniterealtime.smack:smack-android-extensions:4.2.0-beta2'
    compile 'org.igniterealtime.smack:smack-tcp:4.2.0-beta2'
    compile 'com.android.support.constraint:constraint-layout:1.0.0-beta2'
    compile 'com.android.support:design:24.2.1'
    compile 'com.android.support:recyclerview-v7:24.2.1'
    compile 'com.orhanobut:logger:1.15'
    compile 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
    compile 'com.github.Slyce-Inc:SlyceMessaging:1.1.2'
    compile 'io.realm:android-adapters:1.4.0'
    compile 'com.google.code.gson:gson:2.6.2'
    compile 'com.android.support:cardview-v7:24.2.1'
    compile 'com.rengwuxian.materialedittext:library:1.8.3'
    compile 'com.android.volley:volley:1.0.0'
    compile 'com.squareup.okhttp3:okhttp:3.3.0'
    compile 'com.google.firebase:firebase-messaging:9.8.0'
    testCompile 'junit:junit:4.12'
    testCompile 'org.robolectric:robolectric:3.0'
    testCompile 'com.android.support:appcompat-v7:24.2.1'
    testCompile 'org.igniterealtime.smack:smack-tcp:4.2.0-beta2'
    testCompile 'com.android.support.constraint:constraint-layout:1.0.0-beta2'
    testCompile 'com.android.support:design:24.2.1'
    testCompile 'com.orhanobut:logger:1.15'
    testCompile 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
    testCompile 'com.github.Slyce-Inc:SlyceMessaging:1.1.2'
}
apply plugin: 'com.google.gms.google-services'

And the firebase console.

enter image description here

How can I solve it?

Note, that json files are each one of their project.



Solution 1:[1]

  1. Just go to the google-services.json
  2. change the package-name to the name of your package
{
  "client_info": {
    "mobilesdk_app_id": "1:113908578702:android:a0a98decfd9f22466f4cdf",
    "android_client_info": {
      "package_name": "com.example.Appname"
    }
  }
}
  1. sync your project, it'll be solved

Solution 2:[2]

I was facing the same error. I am using multiple flavors. Therefore, I put the google-services.json in app/src/{flv} directory.

It worked well for one flavor but did not work for others. The issue was that I have also placed google-services.json corresponding to flavor for which it was working in app directory also.

Google will search for sub-directories / flavor directories only if it did not find the google-services.json in the app directory.

So, make sure you don't put google-services.json in app directory in case you have separate google-services.json for multiple flavors.

Please see this article for mode details on Android product flavors.

Solution 3:[3]

I had the same problem, so using Android Studio 2.3.3 I used the menu Tools> Firebase - on the right side of the window click Notifications and then Recieve notifications on your app,finally click Connect to Firebase, after this you will see a dialog saying This app is already connected to a project but just click Sync, then firebase will sync automatically all your app clients and it will fix this issue,by the way I know it's too late to respond but it might help someone.

Solution 4:[4]

If you have added google-service.json file check build.gradle(: app) package_name and in google-service.json file package_name is the same
Also if you have added productFlavors make sure you have added that package in firebase for creating JSON file

Solution 5:[5]

Check your Gradle app level applicationId, it should be same as firebase package name, then it works like a charm

Solution 6:[6]

*Go to build.gradle and change the package name with same as AndroidManifest.xml and sync again * [1][In this image show package name in AndroidManifest same as build.gradle] [1]: https://i.stack.imgur.com/T4cqz.png [Below image show package name in build.gradle same as AndroidManifest] [2]: https://i.stack.imgur.com/ModHS.png [package name in build.gradle][2]

Also check firebase and download recent .json file.

Solution 7:[7]

Update your applicationId inside defaultConfig of app level gradle file. With your package name.

Solution 8:[8]

Try to download the latest google-services.json file

Solution 9:[9]

it's a bit late, but maybe it could help someone like me with the same situation. I defined another app in the Firebase console at project settings with a different package name equal to my other flavor build. and then I downloaded the new google-services.json file and used it.it worked like a charm for me

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jawad
Solution 2
Solution 3
Solution 4 Michel Floyd
Solution 5 Carlos Jesus Arancibia Taborga
Solution 6
Solution 7 Dildarkhan Pathan
Solution 8 Abdul Basit Rishi
Solution 9