測試您的 Crashlytics 實施

強制崩潰來測試您的實施

  1. 找到一個現有的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 reports 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");
            }
        }
    }
    
  2. 建立您的應用程式並在建置完成後上傳符號資訊。

    • iOS+ :Firebase Unity 編輯器外掛程式會自動設定您的 Xcode 專案以上傳符號檔案。

    • Android :對於使用 IL2CPP 的 Android 應用,請執行 Firebase CLI crashlytics:symbols:upload指令來上傳符號檔。

  3. 運行您的應用程式。應用程式運行後,觀察設備日誌並等待CrashlyticsTester觸發異常。

    • iOS+ :在 Xcode 底部窗格中查看日誌。

    • Android :透過在終端機中執行以下命令來查看日誌: adb logcat

  4. 前往 Firebase 控制台的Crashlytics 儀表板以查看測試當機。

如果刷新控制台後五分鐘後仍未看到測試崩潰,請嘗試啟用偵錯日誌記錄(下一部分)。

為 Crashlytics 啟用調試日誌記錄

如果您在 Crashlytics 儀表板中沒有看到測試崩潰,則可以使用 Crashlytics 的偵錯日誌記錄來幫助追蹤問題。

  1. 透過將以下程式碼新增至您的應用程式初始化中,為 Firebase 啟用偵錯日誌記錄:

    Firebase.FirebaseApp.LogLevel = Firebase.LogLevel.Debug;
  2. 強制測試崩潰。本頁的第一部分描述如何執行此操作。

如果五分鐘後您沒有在 Firebase 控制台的 Crashlytics 資訊中心中看到來自 Firebase 的日誌或測試崩潰,請聯絡Firebase 支援並提供日誌輸出的副本,以便我們可以協助您進一步排除故障。

下一步

  • 透過新增選擇加入報告、日誌、金鑰和非致命錯誤追蹤來自訂崩潰報告設定