unity 匯入Firebase出現的坑
阿新 • • 發佈:2021-11-03
最近公司專案需要接入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
錯誤二
如果按照官方流程的話,可能還會出現一個錯誤,無法找到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.