others-how to solve No matching client found for package name error when building android app ?

1. Purpose

In this post, I will demonstrate how to solve the following error when trying to build an android app:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processReleaseGoogleServices'.
> No matching client found for package name 'com.bswen.app'

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.7.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 1s
25 actionable tasks: 25 executed

the core error :

Execution failed for task ':app:processReleaseGoogleServices'.
> No matching client found for package name 'com.bswen.app'



2. Solution

You can see that the build process is interrupted when trying to process GoogleServices, it complains that there is no matching client found for package xxxx.

Why does this error happen? What does it mean?

For my app, there are many build flavors in my app, for example proCnRelease, and I use google firebase to collect exceptions and user metrics. For google firebase, it needs your app to put a google-services.json into your app for every build flavor.

If you have three build flavors: default,proCn, proEn,then the directory structure should be follows:

app/src/
    main/google-services.json
    proCn/google-services.json
    proEn/google-services.json
    ...

I think this error happens when the google-services.json does not match current build flavor ,e.g. No matching client found for package name ‘com.bswen.app’ , I am pretty sure that the “package_name” in google-services.json is not matching with your “applicationId” in app gradle.

You can verify it by opening your google-services.json and check the package_name in it:

"client_info": {
    "mobilesdk_app_id": "1:65968121420689:android:78d6f25f5006146",
    "android_client_info": {
      "package_name": "com.bswen.app"
    }

The package_name should match the applicationId in your build.gradle:

defaultConfig {
        applicationId "com.bswen.app" //replace with the package_name in google-services.json =
        minSdkVersion 26
        targetSdkVersion 31
        versionCode 1
        versionName "1.0"
    }

So the solution is easy: Just make sure the package_name and applicationId must be same.

Another possible solution is to remove the google firebase and google service plugin in your build.gradle: remove the google service plugin from your app’s build.gradle

//apply plugin: 'com.google.gms.google-services'

and delete all the google-services.json from your source directories.



3. Summary

In this post, I demonstrated how to solve No matching client found for package name error when building android app. That’s it, thanks for your reading.