firebase / firebase-unity-sdk

The Firebase SDK for Unity
http://firebase.google.com
Apache License 2.0
200 stars 33 forks source link

Failed to read Firebase options from the app's resources #761

Open xjjon opened 1 year ago

xjjon commented 1 year ago

[READ] For Firebase Unity SDK issues, please report to Firebase Unity open-source

Once you've read this section and determined that your issue is appropriate for this repository, please delete this section.

[REQUIRED] Please fill in the following fields:

[REQUIRED] Please describe the issue here:

(Please list the full steps to reproduce the issue. Include device logs, Unity logs, and stack traces if available.)

Error firebase Failed to read Firebase options from the app's resources. Either make sure google-services.json is included in your build or specify options explicitly.

Firebase does not generate the Plugins/Android/FirebaseApp.androidlib & FirebaseCrashlytics.androidlib folders so there is no values/google-services.xml file.

I copied these files from an older install of firebase (2020) and it worked.

Steps to reproduce:

Have you been able to reproduce this issue with just the Firebase Unity quickstarts (this GitHub project)? What's the issue repro rate? (eg 100%, 1/5 etc)

100% repo rate. Fresh 2021 and 2022 LTS projects.

Add google-services.json and GoogleService-Info.plist to root /Assets/ folder

Import Analytics and Crashlytics unitypackage (downloaded latest from firebase site)

Resolve dependencies in dependency resolver.

Add the sample init code and crashlytics test code (from docs)

Build .apk

Check Logcat

2023/06/13 21:26:30.557 19928 20114 Error firebase Failed to read Firebase options from the app's resources. Either make sure google-services.json is included in your build or specify options explicitly.

What happened? How can we make the problem occur? This could be a description, log/console output, etc.

If you have a downloadable sample project that reproduces the bug you're reporting, you will likely receive a faster response on your issue.

xjjon commented 1 year ago

I believe it is related to this:

Sometimes it works and loads properly (which will allow the required google-esrvices.xml files to be generated). But I'm not sure why this is happening.

Assembly 'Assets/Firebase/Editor/Firebase.Editor.dll' will not be loaded due to errors:
Unable to resolve reference 'UnityEditor.iOS.Extensions.Xcode'. Is the assembly missing or incompatible with the current platform?
Reference validation can be disabled in the Plugin Inspector.
Assembly 'Assets/Firebase/Editor/Firebase.Crashlytics.Editor.dll' will not be loaded due to errors:
Unable to resolve reference 'UnityEditor.iOS.Extensions.Xcode'. Is the assembly missing or incompatible with the current platform?
Reference validation can be disabled in the Plugin Inspector.
xjjon commented 1 year ago

Seems that installing iOS build support to my 2022.3 install allowed me to build and confirm that analytics/crashlytics worked. However it didn't generate the required google-services.xml file. See here: https://github.com/googlesamples/unity-jar-resolver/issues/412#issuecomment-724243829

In 2021.3 I was able to get those generated and copied it to my 2022.3 project so it worked as a "fix".

a-maurice commented 1 year ago

Hi @xjjon

Odd that it is still failing to generate the xml file. I assume there are no errors or anything useful in the logs? The script/executable that should do that is in Assets/Firebase/Editor, generate_xml_from_google_services_json.exe (or .py). If you try running that directly, does that give any helpful info?

xjjon commented 1 year ago

hi @a-maurice

I tried to run the .exe (didn't seem to do anything)

Tried to run the python script next. Initially it gave errors:

python Firebase/Editor/generate_xml_from_google_services_json.py
Traceback (most recent call last):
  File "E:\MyProject\Assets\Firebase\Editor\generate_xml_from_google_services_json.py", line 498, in <module>
    sys.exit(main())
             ^^^^^^
  File "E:\MyProject\Assets\Firebase\Editor\generate_xml_from_google_services_json.py", line 355, in main
    with open(input_filename, 'r') as ifile:
         ^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'app/google-services.json'

Wasn't sure the arguments to run it with so i just moved my google-services.json to the default app/google-services.json location.

Ran it again from root /Asset/ folder and it produced the and res/values/google-services.json but in the wrong output directory. (it puts it in the directory i run it from)

The values generated by the .py are correct though (I compared it to the values in downloaded .json)

--

Another issue I noticed is the crashlytics_build_id.xml doesn't get updated. I wasn't able to find out where this is updated from.

a-maurice commented 1 year ago

Alright, that seems to indicate that the problem is on the dll side, and not on the generating the xml from the json at least.

Another thing to try would be on the two Editor dlls (located in Assets/Firebase/Editor), in the Inspector pane turning off "Validate References". Installing the iOS build support should've also resolved that, but maybe something else is going wrong, and that can help?

xjjon commented 1 year ago

I tried that first (before installing iOS build support module) and disabling validation removed the errors in the editor. But it would cause compile errors when building an .apk

There's a similar comment here on this thread: https://github.com/googlesamples/unity-jar-resolver/issues/412#issuecomment-882138839

AlmostMatt commented 1 year ago

@xjjon, Let me know if the following an accurate summary.

1) When trying to build for Android, you encountered this error: Error firebase Failed to read Firebase options from the app's resources. Either make sure google-services.json is included in your build or specify options explicitly.

2) You observed that the following folder does not exist: /Plugins/Android/FirebaseApp.androidlib And so this file also does not exist /Plugins/Android/FirebaseApp.androidlib/res/values/google-services.xml

3) As a workaround, you tried copying that folder and those files from an older version of your project (using Unity 2021?) to the new project. With this workaround you are able to build successfully.

4) In order to try to get google-services.xml generation to work, you also tried:

5) You have tried manually running generate_xml_from_google_services_json.py, and you observe that it was able to read your google-services json file and generated a valid xml file. (You used default input and output directories for the script)

A few questions

AnassCarreau commented 1 year ago

Hi, I have the same problem

xjjon commented 1 year ago

@xjjon, Let me know if the following an accurate summary.

1. When trying to build for Android, you encountered this error:
   `Error firebase Failed to read Firebase options from the app's resources. Either make sure google-services.json is included in your build or specify options explicitly.`

2. You observed that the following folder does not exist:
   /Plugins/Android/FirebaseApp.androidlib
   And so this file also does not exist
   /Plugins/Android/FirebaseApp.androidlib/res/values/google-services.xml

3. As a workaround, you tried copying that folder and those files from an older version of your project (using Unity 2021?) to the new project. With this workaround you are able to build successfully.

4. In order to try to get google-services.xml generation to work, you also tried:

* disabling 'Validate References' on the Editor dlls in Assets/Firebase/Editor (This resulted in compilation errors)

* installing iOS build support module

5. You have tried manually running generate_xml_from_google_services_json.py, and you observe that it was able to read your google-services json file and generated a valid xml file. (You used default input and output directories for the script)

A few questions

* Is all of that accurate?

* When you build for Android, do you see any console logs like "Config File Generation Failed" or "Generation of the Firebase Android resource file ... failed" with additional information about the failure?

* Did installing iOS build support module cause xml generation to work?

Yes that is correct. Copying the google-services.xml and file structure from an older project (i.e. 2021, 2020, etc) worked as long as Validate References was disabled. Validate references fixed the in-editor errors but would cause compilation errors at build time.

After installing iOS build support it worked as expected. I see crashlytics_build_id.xml updating with each build. Also with the debug logging on I see the log messages updating the android manifests with each code reload

Patch Android Manifest with new bundle ID -> myBundleId
PlayServicesResolver initialization succeeded.

So to summarize, installing iOS build support seems to resolve the issue. In previous installs of Unity I only keep Android build support installed on windows environment though. We use a different environment (mac) to build iOS and that one only has iOS build support installed. The workaround we have now is installing both android and iOS on all our environments.

xjjon commented 1 year ago

Didn't mean to close the issue. Re-opening

Orhonbey commented 1 year ago

Hello, I have the same problem, and not fixed. @xjjon thank you. Unity version 2022.3.1f and 2022.3.4f

fuwapaca commented 10 months ago

I have the same problem, after adding ios build support , the firebase script seems to able to generate FirebaseApp.androidlib folder and the xml file inside, and the problem resolved.

nanduzz commented 9 months ago

I have the same problem, and I agree that is related to this:

I believe it is related to this:

Sometimes it works and loads properly (which will allow the required google-esrvices.xml files to be generated). But I'm not sure why this is happening.

Assembly 'Assets/Firebase/Editor/Firebase.Editor.dll' will not be loaded due to errors:
Unable to resolve reference 'UnityEditor.iOS.Extensions.Xcode'. Is the assembly missing or incompatible with the current platform?
Reference validation can be disabled in the Plugin Inspector.
Assembly 'Assets/Firebase/Editor/Firebase.Crashlytics.Editor.dll' will not be loaded due to errors:
Unable to resolve reference 'UnityEditor.iOS.Extensions.Xcode'. Is the assembly missing or incompatible with the current platform?
Reference validation can be disabled in the Plugin Inspector.

but after geting this tip, I went on the Firebase.Editor and disabled the validation for this file, if you click on it, there is a checkbox "Validate References" that I've unchecked. After applying the menu "Window>Firebase" started to show ( wasn't showing previously ) and the folder /Assets/Plugins/Android/FirebaseApp.androidlib was created automaticaly with all the resources inside, including the google-services.xml

BTW, I'm using: Unity 2022.3.7f1 Firebase 11.5.0

lukamix commented 3 weeks ago

I have the same problem, and I agree that is related to this:

I believe it is related to this: Sometimes it works and loads properly (which will allow the required google-esrvices.xml files to be generated). But I'm not sure why this is happening.

Assembly 'Assets/Firebase/Editor/Firebase.Editor.dll' will not be loaded due to errors:
Unable to resolve reference 'UnityEditor.iOS.Extensions.Xcode'. Is the assembly missing or incompatible with the current platform?
Reference validation can be disabled in the Plugin Inspector.
Assembly 'Assets/Firebase/Editor/Firebase.Crashlytics.Editor.dll' will not be loaded due to errors:
Unable to resolve reference 'UnityEditor.iOS.Extensions.Xcode'. Is the assembly missing or incompatible with the current platform?
Reference validation can be disabled in the Plugin Inspector.

but after geting this tip, I went on the Firebase.Editor and disabled the validation for this file, if you click on it, there is a checkbox "Validate References" that I've unchecked. After applying the menu "Window>Firebase" started to show ( wasn't showing previously ) and the folder /Assets/Plugins/Android/FirebaseApp.androidlib was created automaticaly with all the resources inside, including the google-services.xml

BTW, I'm using: Unity 2022.3.7f1 Firebase 11.5.0

I have same issue and this work with me