Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firebase Database 6.16.0 crashes Unity Editor on Install and on Play (with easy fix) #807

Closed
snorrsi opened this issue Oct 5, 2020 · 32 comments
Assignees
Milestone

Comments

@snorrsi
Copy link

snorrsi commented Oct 5, 2020

[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 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.

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.App

mkdir ~/Library/Application\ Support/Is.Company.App

To 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\Local

mkdir %LOCALAPPDATA%\Is.Company.App

Note

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.

@snorrsi snorrsi added the new New issue. label Oct 5, 2020
@snorrsi snorrsi changed the title Firebase Database crashes on Install and on Play (with easy fix) Firebase Database 6.16.0 crashes Unity Editor on Install and on Play (with easy fix) Oct 5, 2020
@ogzavc
Copy link

ogzavc commented Oct 5, 2020

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

image

@snorrsi
Copy link
Author

snorrsi commented Oct 5, 2020

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.

@marnelle1
Copy link

Hi! How to fix this error on Windows?

@Legionair-4
Copy link

Legionair-4 commented Oct 6, 2020

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.

@ogzavc
Copy link

ogzavc commented Oct 6, 2020

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.

@marnelle1
Copy link

Any solution guys?

@napbla
Copy link

napbla commented Oct 6, 2020

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.

@snorrsi
Copy link
Author

snorrsi commented Oct 6, 2020

@nagibator96 I just updated the description.
Just create the folder under %LOCALAPPDATA%

@snorrsi
Copy link
Author

snorrsi commented Oct 6, 2020

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

@ogzavc
Copy link

ogzavc commented Oct 6, 2020

@snorrsi @nagibator96
thanks for the support. I've tried windows solution and worked for me.

@snorrsi
Copy link
Author

snorrsi commented Oct 6, 2020

@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.

@a-maurice a-maurice added type: bug and removed new New issue. labels Oct 6, 2020
@a-maurice a-maurice assigned a-maurice and chkuang-g and unassigned a-maurice Oct 6, 2020
@Legionair-4
Copy link

Cheers for the help I retried the solution this morning and got it working as well.

@chkuang-g
Copy link
Contributor

chkuang-g commented Oct 7, 2020

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

@Aluminum18
Copy link

Solution for Windows works for me. Thanks! :D

@enescang
Copy link

enescang commented Oct 7, 2020

[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 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.

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.App

mkdir ~/Library/Application\ Support/Is.Company.App

To 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\Local

mkdir %LOCALAPPDATA%\Is.Company.App

Note

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.

@bauervision
Copy link

Confirmed the folder fix worked for me. Thanks @snorrsi
2020.1.7f1 Firebase sdk 6.16.0

@PhixDev
Copy link

PhixDev commented Oct 7, 2020

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 :'

Cattura1

Cattura2

@cr4z
Copy link

cr4z commented Oct 7, 2020

Success! napbla's solution worked for me, I created the file and set its name to the bundle identifier found in Player Settings.

@hussaynnasir
Copy link

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 :'

Cattura1

Cattura2

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

@mrpkv
Copy link

mrpkv commented Oct 11, 2020

Thanks a lot @snorrsi!

@snorrsi
Copy link
Author

snorrsi commented Oct 11, 2020

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.

@steve6t6
Copy link

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

@snorrsi
Copy link
Author

snorrsi commented Oct 14, 2020

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.

@steve6t6
Copy link

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

@RamenSea
Copy link

If you want the client to do it on Mac
Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "/Library/Application Support/PACKAGE NAME");

@rexxmagtar
Copy link

rexxmagtar commented Oct 19, 2020

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.

@bhupiister
Copy link

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

@vimanyu
Copy link
Contributor

vimanyu commented Oct 21, 2020

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.

@bhupiister
Copy link

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.

@bhupiister
Copy link

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?

@snorrsi
Copy link
Author

snorrsi commented Oct 23, 2020

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)

@chkuang-g
Copy link
Contributor

chkuang-g commented Oct 27, 2020

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

@firebase firebase locked and limited conversation to collaborators Nov 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests