強制崩潰以測試您的實現
找到一個現有
GameObject
,然後將以下腳本添加到其中。此腳本將在您運行應用程序幾秒鐘後導致測試崩潰。using System; using UnityEngine; public class CrashlyticsTester : MonoBehaviour { int updatesBeforeException; // Use this for initialization void Start () { updatesBeforeException = 0; } // Update is called once per frame void Update() { // Call the exception-throwing method here so that it's run // every frame update throwExceptionEvery60Updates(); } // A method that tests your Crashlytics implementation by throwing an // exception every 60 frame updates. You should see non-fatal errors in the // Firebase console a few minutes after running your app with this method. void throwExceptionEvery60Updates() { if (updatesBeforeException > 0) { updatesBeforeException--; } else { // Set the counter to 60 updates updatesBeforeException = 60; // Throw an exception to test your Crashlytics implementation throw new System.Exception("test exception please ignore"); } } }
構建完成後構建您的應用並上傳符號信息。
iOS+ :Firebase Unity Editor 插件會自動配置您的 Xcode 項目以上傳您的符號文件。
Android :對於使用 IL2CPP 的 Android 應用,運行 Firebase CLI
crashlytics:symbols:upload
命令以上傳符號文件。
運行您的應用程序。一旦您的應用程序運行,請查看設備日誌並等待從
CrashlyticsTester
觸發異常。iOS+ :在 Xcode 的底部窗格中查看日誌。
Android :通過在終端中運行以下命令來查看日誌:
adb logcat
。
當您在設備日誌中看到異常時,請重新啟動您的應用,以便它可以將崩潰報告發送到 Firebase。
轉到 Firebase 控制台的Crashlytics 儀表板以查看您的測試崩潰。
如果您刷新了控制台,但五分鐘後仍未看到測試崩潰,請嘗試啟用調試日誌記錄(下一節)。
為 Crashlytics 啟用調試日誌記錄
如果您在 Crashlytics 儀表板中沒有看到您的測試崩潰,您可以使用 Crashlytics 的調試日誌記錄來幫助追踪問題。
通過將以下代碼添加到您的應用初始化中,為 Firebase 啟用調試日誌記錄:
Firebase.FirebaseApp.LogLevel = Firebase.LogLevel.Debug;
強制測試崩潰。此頁面上的第一部分描述瞭如何執行此操作。
如果您在 5 分鐘後在 Firebase 控制台的 Crashlytics 信息中心中沒有看到來自 Firebase 的日誌或您的測試崩潰,請聯繫Firebase 支持並提供您的日誌輸出副本,以便我們幫助您進一步排查問題。
下一步
- 通過添加選擇加入報告、日誌、密鑰和跟踪非致命錯誤來自定義您的崩潰報告設置。