I had GCM implemented and I am trying to import GCM to FCM now. I dont want to use google-services.json because I want to use different google projects for different environments(Dev, Stag, Prod).
I tried to initialize the app via this code below
FirebaseOptions.Builder options=new FirebaseOptions.Builder();
options.setGcmSenderId("<<project id>>");
options.setApplicationId("<<Project name>>");
FirebaseApp firebaseApp = FirebaseApp.initializeApp(getApplicationContext(),options.build(),"MyTestFCM");
String refreshedToken= FirebaseInstanceId.getInstance(firebaseApp).getToken();
I keep getting exception on Firebase App initialization
Caused by: java.lang.IllegalStateException: FirebaseApp with name [DEFAULT] doesn't exist. Available app names: MyTestFCM
If I remove the app name then i dont get a token back, then when I re-run the application I get a token. I have tried to execute the above piece of code from Mainactivity and Application class. In both places I get the same error.
So my question is how do I initialize Firebase application without using google-services.json
Thanks,
P
Firebase SDK requires to have a "default" project configured via google-services.json
Once you have that you can register FCM sdk with other sender-id using the FirebaseInstanceId.getInstance(context).getToken(...)
But please note that the most recent FCM features (auto-retry of the registration, topic subscriptions) only work with the default project.
So turns out that you need to use google-services.json for FCM, and to handle multiple build variants situation,
Generate respective google-services.json from the firebase console for the different build variants.
Download the google-services.json
In your project create folders for the variants, for example if you want release build, create a folder with name "release" and place the google-services.json in it.
When the app builds, depending upon the build variant it looks for google-services.json in the respective folder and picks up the project details from it.
More details can be found on this thread
google services issues 54
Thanks Arthur Thompson
have you checked to make sure to set your FIREBASE_URL to the right string? Also did you make sure to have the appropriate app setup config?
Last time this happened, I needed to set up my Android App Configs.
https://support.google.com/firebase/answer/7015592
Afterwards, you can follow this setup.
https://firebase.google.com/docs/cloud-messaging/android/client
Please do double check, you added
apply plugin: 'com.google.gms.google-services'
at the bottom of app's gradle file and then clean and rebuild the project
Related
I would like to setup Firebase in Unity 2020.1.14.
I downloaded the GoogleService-Info.plist into my assets folder and set up a project in the Firebase console.
But as soon as I import the FirebaseAnalytics 7.0 package I'm getting this error:
Generation of the Firebase Android resource file google-services.xml from Assets/GoogleService-Info.plist failed.
If you have not included a valid Firebase Android resources in your app it will fail to initialize.
"python" "/Users/joerg/Projekte/UnityTest/FirebaseTest2012042/Assets/Firebase/Editor/generate_xml_from_google_services_json.py" -i "Assets/GoogleService-Info.plist" -l --plist
Could not find key in plist file: [DATABASE_URL]
How do I set the [DATABASE_URL] in GoogleService-Info.plist?
Thanks
Joerg
This was really frustrating. There is no mention on the original setup tutorial about this issue. I'm assuming more people are going to run in to this problem. So here is the solution:
Go to Firebase Console
Choose your project
Go to "Realtime Database"
Create Realtime Database
After database is created.
Go to "Project Settings"
Download google-services.json and GoogleService-Info.plist
Replace these files in you Unity project. (these files should be inside of the Assets folder, or if you've created a Data folder, then you can find them there.)
In the newly generated files there is a "firebase_url":. Which was missing before. This should now fix this particular error message.
Ok, I found the solution: I just had to setup a database in the Firebase Console and then the url is written to the plist file.
This wasn't mentioned in the Google tutorial.
Simple solution, just add those lines:
<key>DATABASE_URL</key>
<string>https://unexisting.fake.database.firebaseio.com</string>
p.s. I would not recommend enabling database service since it's paid. If for some reason, some plugin will attempt to use it in some way, you will be charged. The only reason I am not using those awesome paid services from Google is that they are only POST PAID without ability to set limit (except you wrote some complicated script yourself which will run in real time and will turn off services once you reach certain limit). There are lot of developers stories who woke up with 5-10k bills due to some error in script.
I tried new Firebase Crashlytics SDk after migrating from Fabric and seem to run into a weird issue.
Crash logs are not captured in dashboard after upgrading firebase-crashlytics to 17.0.0 and I get this error in log:
E/FirebaseCrashlytics: Failed to retrieve settings from https://firebase-settings.crashlytics.com/spi/v2/platforms/android/gmp/XXXX/settings
and I followed all instructions from firebase console quickstart guide. Please help me if any one have faced similar issue.
In my case, I had migrated the release version but I guess I never enabled Crashlytics on the Firebase console for the debug variant.
A simple mistake, but putting it here in case it helps out someone else.
If you enabled multiple apps in single project, ensure you choose the correct one (left drop down menu choose the correct project which hold the multiple apps, right drop down menu choose the correct running app). I made such mistake and keep looking on the wrong app page and enabling Crashlytics on the wrong app and of course I get that error "Failed to retrieve settings from https://...:
In my case, There was a legacy firebase project which using same package name of app. When I deleted legacy firebase project and It's works like a charm!
Firebaser here -
We often see these kinds of errors after upgrading due to some sort of configuration error when you were switching out your dependencies. Did you make sure to follow all the steps in this guide?
You may also want to enable Crashlytics debug logging and force a test crash to see if the logs give you any other output. And it may help to edit your original question with your Gradle files and any other relevant Crashlytics setup.
Same problem here with 17.2.1, one of my app flavours didnt't work throwing above error. Removing current apps and re-adding them in firebase project settings solved the problem for me.
We had an issue with the firebase apps and had to re-create the android app on firebase. This meant I had to update the google-services.json file.
After doing this, firebase remote config worked but analytics and crashlytics did not.
Turns out android studio was using-an auto generated file values.xml. This contained
<string name="google_app_id" translatable="false">1:xxxxxxx:android:yyyyyyyy</string>
The yyyyyy part of it was still using the old value from the previous google-services.json file. Deleting this file for all flavors, debug and release builds, coupled with an invalidate caches + restart
might do the trick, but just to be safe, what fixed it for me was:
commenting all the firebase libs from all gradle files
syncing gradle
project will not compile at this points since it cant find Firebase dependencies
invalidate caches + restart
uncomment firebase libs in all gradle files
sync gradle
run app and check if firebase crashlytics works
I am using Android studio 4.1.2
If you have changed the google-services.json file, i.e changed it with a one from a different project, you should do the following:
Comment out all the crashlytics dependencies in the gradle files
Build the app
Invalidate cache and restart
Uncomment crashlytics dependencies and rebuild app
This should fix the problem if it's caused by cached values from the previous json file for crashlytics.
I have a app with Google Sign-In integrated with Firebase. I recently changed app package name for release purpose. and now running throwing this error:
Error:Execution failed for task ':app:processDebugGoogleServices'.
> No matching client found for package name '<Package Name>'
So I am guessing Firebase cant recognize app with the new package name. How can I change Firebase package name. I have gone through Firebase console but can't find any changing package settings. Or is there any good way to achieve this instead of creating new project with package name and code again? Any help would be appreciated.
As Eurosecom commented, you can just add a new Android app to your existing Firebase project with the new package name. After doing this, download the updated google-services.json and add it to your app.
Note that Firebase does not use the actual package name from your Java code, but uses the applicationId from your app's build.gradle file:
defaultConfig {
applicationId "com.firebase.hearthchat"
When you initially create a project in Android Studio, the package name and application id will have the same value. But if you refactor your code into a different package, the application id won't be updated. That explains why the app will continue to work after such a refactoring. But it can be confusing at times, which is why I prefer keeping them in sync.
If you are using Firebase assistant then:
Delete your app in the Firebase console in the project settings.
Back in Firebase assistant reconnect to the Firebase for any service.
It will ask you to sync with the project. Click on Sync.
The app with new package will be added and the google-services.json file will be automatically updated.
Also note that the package name of the applicationId value in the build.gradle file is considered.
Cheers
There's a better way of resolving this issue.The error can be as result of you having a GoogleService Json file in your app folder, All you need to do is; try and locate your google-service.json file under app folder, and change the package_Id to the new package_id you have created; Save, Do a Clean and Rebuild Project, your problem would be resolve. Hope this will help you. It works for me. You can kindly votes if this also help you. Thanks
Firebase crash is a cool tool but as fair as I know there is not any way to programmatically upload Proguard mapping file via API after a build.
Recently, "automate file uploads" options appairs but no info are actually aviable in the learn more link.
Does anyone know something more?
On 15th December the Crash Reporting plugin was released by google: it will generate a gradle task that performs the upload of ProGuard mappings file to Firebase Crash.
Here the steps to use it:
https://firebase.google.com/docs/crash/android#uploading_proguard_mapping_files_with_gradle
Unfortunately, this looks to be an IOS only feature right now: https://firebase.google.com/docs/crash/ios#upload_symbol_files.
Upload symbol files
In order to view human friendly crash reports, you need to upload symbol files after each build. This can be done automatically by adding a run script to Xcode.
Download a service account key to authenticate your uploads. From the Firebase console, select your project and then click Generate New Private Key.
In Xcode, click on your application target, select Build Phases, and click + to add a phase.
Select Run Script and add the following content, setting appropriate values for your service account path and GOOGLE_APP_ID:
Replace this with the GOOGLE_APP_ID from your GoogleService-Info.plist file
GOOGLE_APP_ID=1:my:app:id
Replace the /Path/To/ServiceAccount.json with the path to the key you just downloaded
"${PODS_ROOT}"/FirebaseCrash/upload-sym "/Path/To/ServiceAccount.json"
Note: If your service account key changes, reset your OAuth credentials by running this command:
rm $HOME/Library/Preferences/com.google.SymbolUpload*
I want to know if package name, defined on Firebase project console, is tightly related to Firebase Cloud Message successful delivery or it's just a helper for creating google-services.json file.
On Firebase console, once created it can't be renamed.
In my case I created a project at Firebase console named, by mistake, son.example.firecm instead of com.example.firecm as defined on my Android Studio Project.
My Android project was not compiling cause gap on spelling at google-services.json.
Once renamed package name to com.example.firecm, it compiled but not sure if it will receive Firebase Cloud Messages or not cause difference between Firebase console project package definition at Android Studio project.
Having the right package name is important for several services, though not FCM specifically, other than getting it right in the google-services.json as you found. FCM uses the project number to identify the app, which will be read from the JSON file.
The best thing to do is just to connect a new Android app to your Firebase project with the correct package name, and download the updated google-services.json. It wont hurt to have the other package name connected (and once the console allows deleting connected apps, you should be able to remove it).
Well I did further research on the same.
I found that if package name defined on Firebase Console isn't the same as defined on Gradle and Manifest of the APP, then the APP won't be able to receive Notifications sent from Firebase Console.
In guess that in some way it's logic that package name must match in order to Android lunch the correct APP once notification arrives.
To sumarize, it's mandatory that both names matches.
I invite to test by yourself and keep and eye on package names for project success.