unity 導入Firebase出現的坑



最近公司項目需要接入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文件的配置,報錯就解決了


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM