firebase / quickstart-unity

Firebase Quickstart Samples for Unity
https://firebase.google.com/games
Apache License 2.0
819 stars 424 forks source link

Generation of the Firebase Android Resource File Failing Again #1340

Closed TyelorD closed 1 year ago

TyelorD commented 1 year ago

I started integrating Firebase Analytics into our Unity Project yesterday, and today we are now getting the following error:

Generation of the Firebase Android resource file google-services.xml from [Unity Project]/Assets/../Assets/Configs/Firebase/google-services.json failed.
If you have not included a valid Firebase Android resources in your app it will fail to initialize.

"python3" "[Unity Project]/Assets/Firebase/Editor/generate_xml_from_google_services_json.py" -i "[Unity Project]/Assets/../Assets/Configs/Firebase/google-services.json" -o "[Unity Project]/Assets/../Assets/Plugins/Android/FirebaseApp.androidlib/res/values/google-services.xml" -p "com.exceptionullgames.golftower"

Traceback (most recent call last):
  File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/xml/etree/ElementTree.py", line 762, in _get_writer
    write = file_or_filename.write
AttributeError: 'str' object has no attribute 'write'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "[Unity Project]/Assets/Firebase/Editor/generate_xml_from_google_services_json.py", line 498, in <module>
    sys.exit(main())
  File "[Unity Project]/Assets/Firebase/Editor/generate_xml_from_google_services_json.py", line 490, in main
    tree.write(output_filename, 'utf-8', True)
  File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/xml/etree/ElementTree.py", line 732, in write
    with _get_writer(file_or_filename, enc_lower) as write:
  File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/contextlib.py", line 117, in __enter__
    return next(self.gen)
  File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/xml/etree/ElementTree.py", line 768, in _get_writer
    file = open(file_or_filename, "w", encoding=encoding,
PermissionError: [Errno 13] Permission denied: '[Unity Project]/Assets/../Assets/Plugins/Android/FirebaseApp.androidlib/res/values/google-services.xml'

You can start to diagnose this issue by executing ""python3" "[Unity Project]/Assets/Firebase/Editor/generate_xml_from_google_services_json.py" -i "[Unity Project]/Assets/../Assets/Configs/Firebase/google-services.json" -o "[Unity Project]/Assets/../Assets/Plugins/Android/FirebaseApp.androidlib/res/values/google-services.xml" -p "com.exceptionullgames.golftower"" from the command line.
UnityEngine.Debug:LogError (object)
Firebase.Editor.GenerateXmlFromGoogleServicesJson:RunResourceGenerator (System.Collections.Generic.IEnumerable`1<string>,string,bool) (at /Users/runner/work/firebase-unity-sdk/firebase-unity-sdk/editor/app/src/GenerateXmlFromGoogleServicesJson.cs:545)
Firebase.Editor.GenerateXmlFromGoogleServicesJson:GenerateXmlResources (string,bool) (at /Users/runner/work/firebase-unity-sdk/firebase-unity-sdk/editor/app/src/GenerateXmlFromGoogleServicesJson.cs:588)
Firebase.Editor.GenerateXmlFromGoogleServicesJson:UpdateJson (bool,Firebase.Editor.GenerateXmlFromGoogleServicesJson/LogMessage,Firebase.Editor.GenerateXmlFromGoogleServicesJson/LogMessage) (at /Users/runner/work/firebase-unity-sdk/firebase-unity-sdk/editor/app/src/GenerateXmlFromGoogleServicesJson.cs:165)
Firebase.Editor.GenerateXmlFromGoogleServicesJson:UpdateJsonWithBundleIdChooserDialog (string,bool) (at /Users/runner/work/firebase-unity-sdk/firebase-unity-sdk/editor/app/src/GenerateXmlFromGoogleServicesJson.cs:481)
Firebase.Editor.GenerateXmlFromGoogleServicesJson:CheckConfiguration () (at /Users/runner/work/firebase-unity-sdk/firebase-unity-sdk/editor/app/src/GenerateXmlFromGoogleServicesJson.cs:254)
Firebase.Editor.GenerateXmlFromGoogleServicesJson/<>c:<.cctor>b__15_1 () (at /Users/runner/work/firebase-unity-sdk/firebase-unity-sdk/editor/app/src/GenerateXmlFromGoogleServicesJson.cs:103)
Google.EditorInitializer/<InitializeOnMainThread>c__AnonStorey1:<>m__2 () (at /Users/chkuang/Workspace/git/unity-jar-resolver/source/VersionHandlerImpl/src/EditorInitializer.cs:60)
Google.RunOnMainThread:ExecutePollingJobs () (at /Users/chkuang/Workspace/git/unity-jar-resolver/source/VersionHandlerImpl/src/RunOnMainThread.cs:409)
Google.RunOnMainThread:<ExecuteAllUnnested>m__12 () (at /Users/chkuang/Workspace/git/unity-jar-resolver/source/VersionHandlerImpl/src/RunOnMainThread.cs:541)
Google.RunOnMainThread:RunAction (System.Action) (at /Users/chkuang/Workspace/git/unity-jar-resolver/source/VersionHandlerImpl/src/RunOnMainThread.cs:343)
Google.RunOnMainThread:ExecuteAllUnnested (bool) (at /Users/chkuang/Workspace/git/unity-jar-resolver/source/VersionHandlerImpl/src/RunOnMainThread.cs:530)
Google.RunOnMainThread:ExecuteAll () (at /Users/chkuang/Workspace/git/unity-jar-resolver/source/VersionHandlerImpl/src/RunOnMainThread.cs:512)
UnityEditor.EditorApplication:Internal_CallUpdateFunctions () (at /Users/bokken/build/output/unity/unity/Editor/Mono/EditorApplication.cs:356)

As far as I can see this seems to be the same, or a very similar issue to this closed issue.

However following the steps for the work-around patm1987 provided still leaves me with the same exact error message as before and doesn't seem to fix anything for us...

This has been a big headache, especially from the confusion caused by this issue too.

Reproduction Steps:

  1. Make a new Unity Project
  2. Create a Unity project on the Firebase Console
  3. Follow the steps in the Firebase Console guide to download and import the .json and .plist files for Android and iOS
  4. Import the .unitypackage given by the Firebase Console
  5. Start logging analytics while running the game in Play Mode
  6. End Play Mode in the editor and then observe the error message in the Unity Console.
google-oss-bot commented 1 year ago

This issue does not seem to follow the issue template. Make sure you provide all the required information.

TyelorD commented 1 year ago

This issue appears to be related to version controlling.

Specifically Perforce sets all files to Read Only upon submission, and having the generated: google-services.xml file marked as "Read Only" was breaking the functionality for the python script here.

AlmostMatt commented 1 year ago

Thanks for sharing the additional information about the cause of the issue.

In this case, I think it is correct for Firebase to be unable to modify a read-only file, so I am going to close this issue. If anyone else encounters the same problem, they should be able to look into perforce settings to find a way to not mark the file as read only.