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:
- My custom
byildType
for debugging suffixes.debug
to theapplicationId
(package name). Is there a way I can make it work with thegoogle-services.json
which has my releaseapplicationId
(i.e. without the suffix.debug
) - 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 toapp
folder. I know it can be done usingtask
as mentioned in this post. Is there a simpler way to just have one file or pick right file based on gradle configuration? - I see the
package_name
field ingoogle-services.json
has the package namecom.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.
First off, add a suffix to the application package in Gradle:
This will cause your package to be named
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:
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.
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 forapplicationId
(withinandroid
,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
.If your package name on Google-services.json file is okay, Go to gradle.properties file. Then change your APPLICATION_ID="com.yourpackage.name"
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.
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.