unity 导入Firebase出现的坑

2022-04-08 00:00:00 专区 文件 项目 错误 接入

近公司项目需要接入google的firebase sdk,来更好的分析用户行为。接入流程到firebase官网选择unity项目按照流程走就好了。接入完后出现了几个错误

错误一

Generation of the Firebase Android resource file google-services.xml from Assets/google-services.json failed.
If you have not included a valid Firebase Android resources in your app it will fail to initialize.
`F:/unity/50_Shopping_Island/../Assets/Firebase/Editor/generate_xml_from_google_services_json.exe -i "Assets/google-services.json" -l`.
Error loading Python DLL: C:\Users\ftb\AppData\Local\Temp\_MEI59722\python27.dll (error code 14001)

说是firebase初始化失败了,因为下载Python DLL失败。在网上查了一圈,似乎是因为win7系统和python版本的问题。后找到了一个很好的解决方案。用pyinstaller重建generate_xml_from_google_services_json.py脚本。

解决步骤

  • 确保python环境变量已经配置好

  • 创建一个空文件夹,将项目路径\Assets\Firebase\Editor\下的generate_xml_from_google_services_json.py文件复制到空文件夹下。

  • 打开generate_xml_from_google_services_json.py文件,添加这两行


  • 在这个文件夹下启动命令行工具,执行pip install pyinstaller命令

  • 执行以下命令

pyinstaller --clean --win-private-assemblies -F generate_xml_from_google_services_json.py
  • 后会生成一个dist文件,将文件的exe复制并且覆盖unity项目路径\Assets\Firebase\Editor\中的同名文件

错误二

如果按照官方流程的话,可能还会出现一个错误,无法找到google-services.json文件中的一个字段。

Generation of the Firebase Android resource file google-services.xml from Assets/Firebase/GoogleService-Info.plist failed.

If you have not included a valid Firebase Android resources in your app it will fail to initialize.

"python" "/Users/xxxxx/Documents/ProgrammingCloud/Unity/yyyyy/Assets/Firebase/Editor/generate_xml_from_google_services_json.py" -i "Assets/Firebase/GoogleService-Info.plist" -l --plist

Could not find key in plist file: [DATABASE_URL]

You can start to diagnose this issue by executing ""python" "/Users/xxxxx/Documents/ProgrammingCloud/Unity/yyyyy/Assets/Firebase/Editor/generate_xml_from_google_services_json.py" -i "Assets/Firebase/GoogleService-Info.plist" -l --plist" from the command line.

解决方法:

1.在firebase面板中创建一个Realtime Database.

2.重新下载google-services文件,替换原来Asset文件下的google-services文件


后文件中会多出一个firebase_url文件的配置,报错就解决了

相关文章