After installing Firebase Database version 6.16.0 using Unity Package Manager pressing Play in project which uses Firebase Database crashes the Unity Editor.
The Editor also did crash when installing Firebase Database through UPM
In the Unity Editor.Log I can see:
ERROR: Could not initialize persistence: Unable to find app data directory.
This seems to be causing the crash.
After looking at the Firebase Database C++ code I found out what was causing this error.
It's quite obvious as the error message can be found in database/src/desktop/core/repo.cc
By looking at that file I saw the cause was relating to GetAppDataPath
On Mac GetAppDataPath seems to be finding the Application Support directory and appending the package_name to that if that folder exists.
It seems to be using package_name for the folder which is according to the xml converter created from the bundle_id.
In my case the bundle_id was: Is.Company.App
Which lead me to the conclusion that Firebase Database was looking for the folder path
~/Library/Application Support/Is.Company.App
That folder did not exists which explained the error.
I therefore created it and after that the Unity Editor ran without crashing and I saw data being created in a subfolder of the folder I just created and no error in Unity logs.
Install Firebase Database 6.16.0 through Unity Package Manager.
Firebase Database might fail on install.
Create scene and c# files which starts Firebase App.
Press Play and see if crash occurs.
If the Unity Editor crashes then open Unity Editor.Log and look for:
ERROR: Could not initialize persistence: Unable to find app data directory.
For Firebase App with bundle id (package_name): Is.Company.App
Just create the folder: ~/Library/Application Support/Is.Company.App
mkdir ~/Library/Application\ Support/Is.Company.App
For Firebase App with bundle id (package_name): Is.Company.App
Just create the folder: C:Users[username]\AppData\Local\Is.Company.App
The folder is in path (see set) such as fx.:
LOCALAPPDATA=C:Users[username]\AppData\Local
mkdir %LOCALAPPDATA%\Is.Company.App
You might need to use upper or lowercase package_name. Just try according to your bundle_id or package_name stated in google-services.json
I did not help to downgrade to 6.15.2 and then install 6.16.0 again.
Hello,
I'm facing with same issue when i try to set databaseReference as FirebaseDatabase.DefaultInstance.RootReference.
and i tried to create folder in ~\Library\Application Support\com.packagename but did not solve my problem.
I've captured console error before unity crash it looks like this

Hi @ogzavc, it seems you have the same error as I had.
Did you change the permission of the folder as well with the chmod command ?
Make sure you are using package_name or bundle_id according to fx. google-services.json
I used the uppercase version from bundle_id but maybe the lower case version might work for you. My Mac is not case sensitive.
Hi! How to fix this error on Windows?
Hi, I have this exact same error and for the life of me have not been able to resolve it.
Using Windows,
Unity version 2020.1.0f1
FirebaseDatabase.unitypackage for dotnet4 v6.16.0
I have tried earlier versions of both Unity and the Firebase database, also using the dotnet3 sdks (with little hope) however still no luck. I took at look at trying to implement your solution above but cannot seem to get it working for me on Windows.
If you go to Assets>External Dependency Manager>Android Resolver>Settings and then scroll to the bottom, it does indicate that 'Custom Gradle Properties Template' should be checked under Publishing Settings in the Player tab on versions of Unity > 2019.3 however this did nothing for my issue.
Hi @ogzavc, it seems you have the same error as I had.
Did you change the permission of the folder as well with the chmod command ?
Make sure you are using package_name or bundle_id according to fx. google-services.json
I used the uppercase version from bundle_id but maybe the lower case version might work for you. My Mac is not case sensitive.
Hi, actually i'm working on windows pc, so i think i dont have to give permission. But i've tried to run unity as administrator and i've changed folder name to lowercase and both solutions did not help to me.
Any solution guys?
Thanks @snorrsi it worked like a charm. In my case, just creating the folder did fix the crash. I even do not need to "chmod" to 777.
@ogzavc I used the Bundle Identifier in Player Settings as the folder name.
@nagibator96 I just updated the description.
Just create the folder under %LOCALAPPDATA%
Hey @chkuang-g , first of all thanks for fixing the gc alloc issue.
Can you comment on this issue? Seems I'm not the only one having problem with Firebase Database 6.16.0
@snorrsi @nagibator96
thanks for the support. I've tried windows solution and worked for me.
@ogzavc great to hear.
@napbla thanks for pointing out the chmod not being needed. I put it just in case but have now removed the command.
Cheers for the help I retried the solution this morning and got it working as well.
Hi folks,
I can reproduce this issue locally. As @snorrsi mentioned, this issue is in C++ code.
https://github.com/firebase/firebase-cpp-sdk/blob/master/database/src/desktop/util_desktop_macos.mm#L33
https://github.com/firebase/firebase-cpp-sdk/blob/master/database/src/desktop/util_desktop_windows.cc#L50
app_name here is actually [bundle-id]/[firebase-domain-name].
Seems like the Linux code would attempt to create both folders but not for Mac and Windows version. 馃槥
I'm currently working on a patch for this and should be included in the next patch release.
Shawn
Solution for Windows works for me. Thanks! :D
[REQUIRED] Please fill in the following fields:
* Unity editor version: 2019.4.11f * Firebase Unity SDK version: 6.16.0 * Source you installed the SDK: Unity Package Manager (.unitypackage or Unity Package Manager) * Problematic Firebase Component: Database * Other Firebase Components in use: Auth, Crashlytics, Messaging, Functions * Additional SDKs you are using: Facebook, Leanplum, Amplitude, Branch (does not apply) * Platform you are using the Unity editor on: Mac * Platform you are targeting: iOS, Android * Scripting Runtime: Mono, and/or IL2CPP[REQUIRED] Please describe the issue here:
After installing Firebase Database version 6.16.0 using Unity Package Manager pressing Play in project which uses Firebase Database crashes the Unity Editor.
The Editor also did crash when installing Firebase Database through UPMIn the Unity Editor.Log I can see:
ERROR: Could not initialize persistence: Unable to find app data directory.This seems to be causing the crash.
After looking at the Firebase Database C++ code I found out what was causing this error.
It's quite obvious as the error message can be found in database/src/desktop/core/repo.cc
By looking at that file I saw the cause was relating to GetAppDataPath
On Mac GetAppDataPath seems to be finding the Application Support directory and appending the package_name to that if that folder exists.
It seems to be using package_name for the folder which is according to the xml converter created from the bundle_id.In my case the bundle_id was: Is.Company.App
Which lead me to the conclusion that Firebase Database was looking for the folder path
~/Library/Application Support/Is.Company.AppThat folder did not exists which explained the error.
I therefore created it and after that the Unity Editor ran without crashing and I saw data being created in a subfolder of the folder I just created and no error in Unity logs.
Steps to reproduce:
Install Firebase Database 6.16.0 through Unity Package Manager.
Firebase Database might fail on install.
Create scene and c# files which starts Firebase App.
Press Play and see if crash occurs.
If the Unity Editor crashes then open Unity Editor.Log and look for:
ERROR: Could not initialize persistence: Unable to find app data directory.To fix for MacOS
For Firebase App with bundle id (package_name): Is.Company.App
Just create the folder: ~/Library/Application Support/Is.Company.Appmkdir ~/Library/Application\ Support/Is.Company.AppTo fix for Windows
For Firebase App with bundle id (package_name): Is.Company.App
Just create the folder: C:Users[username]\AppData\Local\Is.Company.App
The folder is in path (see set) such as fx.:
LOCALAPPDATA=C:Users[username]\AppData\Localmkdir %LOCALAPPDATA%\Is.Company.AppNote
You might need to use upper or lowercase package_name. Just try according to your bundle_id or package_name stated in google-services.json
I did not help to downgrade to 6.15.2 and then install 6.16.0 again.
That is worked for Windows for me. Unity 2019.4.0f1 and firebase_unity_sdk_6.16.0 . Thanks.
Confirmed the folder fix worked for me. Thanks @snorrsi
2020.1.7f1 Firebase sdk 6.16.0
Hi, i've resolved the same problem adding the folder to the path... but i have another problem... now my console give me this error... HELP ME PLEASE :'
Success! napbla's solution worked for me, I created the file and set its name to the bundle identifier found in Player Settings.
Hi, i've resolved the same problem adding the folder to the path... but i have another problem... now my console give me this error... HELP ME PLEASE :'
Hi. I'm getting the exact same error. The database reference isn't working in the unity editor but it is working fine in the android build. Any help related to this will be much appreciated
Thanks a lot @snorrsi!
Hi @PhixDev and @hussaynnasir I haven麓t had that issue myself.
You should create a new issue and maybe @chkuang-g can check it out.
Hello
The folder trick worked for a little while, but now I get the same issue again, I removed Firebase entirely and installed it through packages (Not UPM) and the same problem repeated itself. I returned to UPM versions and tried a force resolve, this triggers a Java warning and a "Java runtime missing, please install" error, I am using the built in OpenJDK (Tried uncheck and browse trick) Also JAVA_HOME points at the unity OpenJDK folder.
In my editor logs I see the "Could not initialize persistence: Unable to find app data directory" error and a great many "Fallback handler could not load library" for FirebaseCppApp-6_16_0.bundle and variants.
I have check the security settings and no Firebase packages are listed, although they all were blocked with manual installs and had to be allowed before.
the final error in the log is:
**(lldb) detach
error: Detach failed: Sending disconnect packet failed.
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
[Unity Package Manager (Upm)]
Parent process [566] was terminated**
Running MacOS Catalina 10.15.5 and Unity 2019.3.4f1
hi @steve6t6 ,
have you been switching platforms in Unity ?
I ask because the bundle_id / package_name is not always the same for all operating systems.
Mine are with upper case and also with only lower case letters, if you have case sensitive disc you might run into issues.
Since you are still getting the same error it seems it still Firebase Database can't find the folder it wants.
The other fallback errors happen all the time for me, not sure about the cause there maybe @chkuang-g can explain those.
hi @steve6t6 ,
have you been switching platforms in Unity ?
I ask because the bundle_id / package_name is not always the same for all operating systems.
Mine are with upper case and also with only lower case letters, if you have case sensitive disc you might run into issues.
Since you are still getting the same error it seems it still Firebase Database can't find the folder it wants.The other fallback errors happen all the time for me, not sure about the cause there maybe @chkuang-g can explain those.
Hi Snorrsi
I had checked the package name initially, but your message forced me to look again, then to remember our dev builds target different google-service files where the name was Camel Cased. So thanks to you my app no longer immediately crashes.
Force resolve still won't work and there are 15 shiny new errors to dig into, but it's running. Hopefully @chkuang-g can shed light on the bizzar Force resolve Java fail.
Thanks again @snorrsi
If you want the client to do it on Mac
Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "/Library/Application Support/PACKAGE NAME");
I face the same problem. I am using Windows. I created folder in "Local" folder with the name identical to bundle name written in google-services.json. I tried combine Upper/Lower cases in names. I still have the same error.
Created the folder with the same name as bundle ID on windows and it solved my problem!
for example, on my PC the path was C:Users\home\AppData\Local, I then created folder name com.liftcad.cad
This solution helped me a lot. Huge thanks to @snorrsi
Thank you for your patience. We just released 6.16.1 which should fix issues with creating recursive directories for persistent storage in Realtime Database. Please let us know if you are still seeing issues with it.
Created the folder with the same name as bundle ID on windows and it solved my problem!
for example, on my PC the path was C:Users\home\AppData\Local, I then created folder name com.liftcad.cad
This solution helped me a lot. Huge thanks to @snorrsi
@rexxmagtar But why did you dislike my comment? You could ask for help and would do the needful gladly.
Thank you for your patience. We just released 6.16.1 which should fix issues with creating recursive directories for persistent storage in Realtime Database. Please let us know if you are still seeing issues with it.
Thanks for the update, also would like to know why it shows FirebaseApp.DefaultInstance.SetEditorDatabaseUrl as obsolete and deprecated?
Thank you for your patience. We just released 6.16.1 which should fix issues with creating recursive directories for persistent storage in Realtime Database. Please let us know if you are still seeing issues with it.
Thanks for the update, also would like to know why it shows FirebaseApp.DefaultInstance.SetEditorDatabaseUrl as obsolete and deprecated?
@bhupiister they have deprecated that function but the documentation has not been updated. Maybe @chkuang-g can push that.
You should use AppOptions instead .. check out AppOptions
and how to use it FirebaseApp.Create(AppOptions options)
All of the service account APIs will be removed in the next release, since many of them were temporary solution before we finished desktop implementation.
As @snorrsi, if you like to use a different database in editor, you should be able use FirebaseApp.Create(AppOptions options).
If you need to manage your Firebase project as administrator, by using APIs like SetEditorP12FileName(), it is better to use Admin SDK. Unfortunately we do not have a Unity equivalent of Admin SDK. If this is critical to your business, please file a feature request.
Shawn