Unity Integrated With Firebase Works On Unity Editor But Not On Mobile Device
Solution 1:
I had the same issue with google-services.json not being loaded (Unity 2021.1.4f) and spent a looong time looking for answers and no suggested solutions I found worked. Finaly I tried calling Firebase.Create() manualy with manualy created AppOptions with values copied from google-services.json.
Firebase.AppOptionsoptions=newFirebase.AppOptions();
options.ApiKey = "XXXXXXXXXXX";
options.AppId = "XXXXXXXXXXXX";
options.MessageSenderId = "XXXXXXXXXXXXX";
options.ProjectId = "my-app";
options.StorageBucket = "my-app.appspot.com";
varapp= Firebase.FirebaseApp.Create( options );
Not an ideal solution but works till this bug gets fixed.
Solution 2:
According to your log, you're missing the google-services.json
file required to connect your game to your Firebase backend. There could be multiple reasons and multiple workarounds for this.
Simplest solution:
Make sure that somewhere in your Assets/
directory you have your google-services.json
file. You can download that from the Firebase dashboard if you've forgotten to do so.
From this page:
Get config file for your Android app
Go to your Project settings in the Firebase console.
In the Your apps card, select the package name of the app for which you need a config file.
Click google-services.json.
Modified for Unity: Move your config file into the Assets/ directory of your game.
Make sure that you only have this most recent downloaded config file in your app.
google-services.json exists, I'm still getting the error
Make sure you have python
installed and that you have an executable in your path actually named python
rather than python3
.
Normally, Android developers will use the play services gradle plugin to convert google-services.json
into an xml (the process is detailed here). The Firebase Unity plugin still supports Unity back to 2017, which predates stable support for gradle in games (it used to support back to the 5 branch, but it's old enough that it's hard to find test machines to still run the Editor). Because of this, the Firebase Unity plugin instead runs a python script named generate_xml_from_google_services_json.py
(compiled to generate_xml_from_google_services_json.exe
on Windows), which generates the file Assets/Plugins/Android/FirebaseApp.androidlib/res/values/google-services.xml
. This is usually what's missing when you see an error saying that you're missing a google-services.json
file in the context of Unity.
This script is cross compatible with Python 3 and 2 (2 because that still ships in MacOS), but the tooling tries to execute it with python
in your path. Since you're on Linux, you may want to try poking this bug: https://github.com/firebase/quickstart-unity/issues/1005 (mention @patm1987 in the comments if you think it should be opened and no one's responding -- remind me of this answer).
Neither of these are working
I'd recommend opening a bug here, but there is a workaround for all google-service.json
related issues.
Note that I recommend against this as a first step, as this configuration isn't expected and may throw folks for a loop trying to help you in the future. It's also kind of fragile due to how Unity and Firebase interact.
When you call FirebaseApp.DefaultInstance
or any other .DefaultInstance
on a Firebase class, Firebase.Create()
is implicitly lazily called if there is no FirebaseApp
with the default app name. Because of a bug, you cannot override the default app once it's created (what I mean by this process being fragile) but if you make a call to .Create(AppOptions)
before a default app is created (before any call to .DefaultInstance
in any thread), you can provide your own app options.
You could then shove your google-services.json
in the StreamingAssets/
directory and load it directly, or build an AppOptions
by copy/pasting the fields out of your google-services.json
.
Again, I recommend that this is your last resort rather than your first. And I'd ask that you file a bug if you have to do this.
Post a Comment for "Unity Integrated With Firebase Works On Unity Editor But Not On Mobile Device"