Android. Firebase: Different applicationIdSuffix. Where save google-services.json? - android

I has project with 2 build types.
Every build type has specific applicationIdSuffix.
BuildType : dev , applicationIdSuffix = .dev
BuildType : prod , applicationIdSuffix = .prod
In Firebase console I create application for build type = dev.
As result I download file google-services.json. I put it in c:\myproject\android\app\
In this file "package_name": "com.myproject.dev"
OK. It's work.
Now I in Firebase for the same project, I need to create another application with another buildType = prod.
As result I download NEW file: google-services.json.
In this file "package_name": "com.myproject.prod"
Where I need to put this second file google-services.json?

Firebase already supports that, you should create a new project, then add 2 new apps for each build type (mypackage.prod and mypackage.dev) or flavor.
Once done, just export the google-services.json of the last created app (dev), the file should contain details of both apps, like the following
"client_info": {
"mobilesdk_app_id": "...",
"android_client_info": {
"package_name": "mypackage.dev"
}
},
"client_info": {
"mobilesdk_app_id": "...",
"android_client_info": {
"package_name": "mypackage.prod"
}

You just need to replace the google-services.json with existing one.Because Firebase automatically generates all the necessary attributes in google-services.json file having multiple build flavors in single project
Just remember every-time download new google-services.json and replace it after adding new flavor in your existing project

Related

How to avoid "No matching client found for package name" for google-services.json?

I am using google-services.json file in my app. There is a field in this file
...
"client": [
{
"client_info": {
"mobilesdk_app_id": "my_id",
"android_client_info": {
"package_name": "my_package_name"
}
},
...
Then in order to distinguish between release and debug I added this line in my .gradle file
debug {
...
applicationIdSuffix ".debug"
}
And then I get an error in debug build that my package name in google-services.json not the same with my package name. And I understand this issue, because in google-services.json package name is my_package_name, but after I added that line in my .gradle file my package name in debug build is my_package_name.debug it is not the same.
So, it is means that now I need every time when I switch between release and debug I need go to google-services.json and change it as well.
I almost sure that here should be solution, question is - how to do it correctly? In order to avoid open google-services.json every time when I switch build variant?
You can add another app with .debug suffix to your Firebase project.
So your new google-services.json file will contain both these apps like this:
"client_info": {
"mobilesdk_app_id": "...",
"android_client_info": {
"package_name": "com.company.project.debug"
}
},
"client_info": {
"mobilesdk_app_id": "...",
"android_client_info": {
"package_name": "com.company.project"
}
}
Reference: https://firebase.googleblog.com/2016/08/organizing-your-firebase-enabled-android-app-builds.html
google-services.json file allows several entries for different app flavours that you have. Just go into the Firebase Console and add the new app, set its name to my_package_name.debug. I have about 6-7 different package names for the same app, it just adds another entry in your generated json.

Firebase keeps showing the old package name in google-services.json file

com.myweb.example was my package name, and it was registered in firebase console.
I changed the package name to com.example.newweb, and added a new app in same firebase project with different package name, now when i download google-services.json file, it still shows the old package name in it.
Hence app does not connect with firebase project.
However package name does changes in these 2 places. In rest of 4 places it shows old package name in google-services.json file.
"client_info": { }
"oauth_client": []
I need to know why its showing the old package name in a new app in firebase console.
In google-services.json file contains multiple clients as your apps. so please check the clients key in google-services.json.
this contains all your client apps
{
"client": [
{
"client_info": {
"android_client_info": {
"package_name": "******001" // first app package name
}
}
},
{
"client_info": {
"android_client_info": {
"package_name": "******002" // second app package name
}
}
}
]
}

Gradle Warnings: Could not find google-services.json while looking in [duplicate]

This question already has answers here:
google-services.json for different productFlavors
(28 answers)
Closed 5 years ago.
I got the following warnings.
How can I avoid this warnings?
Could not find google-services.json while looking in
[src/flavor1/debug, src/debug, src/flavor1] Could not find
google-services.json while looking in [src/flavor1/release,
src/release, src/flavor1] Could not find google-services.json while
looking in [src/flavor2/debug, src/debug, src/flavor2] Could not find
google-services.json while looking in [src/flavor2/release,
src/release, src/flavor2]
I added two client_info at app/google-services.json
{
"project_info": {
"project_number": "000000000000",
"project_id": "****-*****"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": ...,
"android_client_info": {
"package_name": "flavor1.package.name"
}
},
...
},
{
"client_info": {
"mobilesdk_app_id": ...,
"android_client_info": {
"package_name": "flavor2.package.name"
}
},
...
}
],
"configuration_version": "1"
}
As per my experience, this will occur when you are using any type of service related to firebase and you have not put the google-services.json the file which we needed to use the service,
The solution is you need to get the file from firebase console and you need to put inside of your app level folder if you are creating a single project in the console for all flavor and If you are creating different one then you need to create a number of files for a number of projects or flavors.
Could not find google-services.json while looking in
According to LOGCAT, google-services.json is absent in right place (Missing).
The google-services.json file is generally placed in the app/ directory (at the root of the Android Studio app module).
Read official guideline about Adding the JSON
For example, dogfood and release are build types.
app/
google-services.json
src/dogfood/google-services.json
src/release/google-services.json
...
Finally, Clean-Rebuild-Run.

Change package name (not only applicationId) for build flavor

When building multiple whitelable apps on the same codebase it's easy to use the build flavor mechanism of Android Studio. I can easily set a new applicationId in build.gradle file.
android {
productFlavors {
original {
applicationId "com.original.myapp"
}
whitelable {
applicationId "com.whitelable.myapp"
}
}
}
Everything's nice BUT the package name of the whitelable app is still com.original.myapp and the component name of the main activity is com.whitelable.myapp/com.original.myapp.MainActivity. Everybody can see that the whitelable app is build upon the original app.
Is the a way to replace the package name for the build flavor so the original package name at least doesn't appear on the flavored app's component names?
The question was asked a long time ago but I'd like to answer it for new folks who will investigate.
First you have to create 2 versions with Flavors.
Then, if you are using it, you need to create the data for the version you just created in the "client": [] section in your google-service.json file. (You can also create a separate google-service.json file for both in their own package folders.)
Then use ${packageName} instead of explicitly typing your package path in the Manifest file with your package path.
I was able to create 2 completely different packageNames by following this way.
Flavors;
flavorDimensions "default"
productFlavors{
product1{
applicationId "com.product.package"
}
product2{
applicationId "com.white.label"
}
}
google-service.json;
I cannot share the google-service.json file, but the data under "client" in the google-service.json file you will receive for your new project via Firebase should be copied and added to the "client" as the second data under the google-service.json file in your project. Sample;
"client": [
{
"client_info": { //Old App Info
data...
},
...
},
{
"client_info": {
//New App Info
data...
},
...
}
]
Manifest;
com.project.package.fileprovider
use this instead
${packageName}.fileprovider

google-services.json - changed package_name - do i need to create a new configuration file

My current environemnt already has a google-services.json file and everything works. But now due to unforeseen circumstance i must rename the package of my project. I have successfully renamed the package now. I also went into the google-services.json file and renamed the package name there as well. So now i am wondering do i need to go back onto the google developer site and create a new configuration file ?
Basically i am concerned that renaming the package namein google-services.json is not sufficient. i think that configuration is tied to the original package name. I am wondering when a developer renames the package name of a project is it necesaary to generate a new configuration file from google developer site ?
Here is the google-services.json file i originally generated and i'll show you how i changed the package name :
{
"project_info": {
"project_number": "987654321",
"project_id": "firebase-project_myapp"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:234567:android:1011212314151617",
"android_client_info": {
"package_name": "com.NewPackageName" //i updated package name
}
},
"oauth_client": [],
"api_key": [
{
"current_key": "adlskfjsd;fjkalskdjfalk;sdfj"
}
],
"services": {
"analytics_service": {
"status": 1
},
"appinvite_service": {
"status": 1,
"other_platform_oauth_client": []
},
"ads_service": {
"status": 1
}
}
}
],
"configuration_version": "1"
}
Again is it sufficientn to to only update package_name in the json file or do i need to create all new projects for my app ?
Changing the package name in the google-services.json file will not work as it does not act as an update mechanism of any sort but merely a repository of data to be used during services instance establishment.
Yes, it is necessary to create a new configuration file by creating a new application or by deleting the current application in the console you can re-use the application name originally used. This is because each google services instance are generated specifically for a particular application tied to the package name with specific identifiers. So it is an absolute necessity to create a new application and use the google-services.json file from that application settings.
It worked for me by just renaming the package from the googleservices.json file.
We need add an app in firebase-console inside the project with new package name and then download and replace that json in the project directory.
Worked for me!

Categories

Resources