測試 Crashlytics 實作 (Unity)

選取平台: iOS+ Android Flutter Unity


如果您已按照入門指南操作,但 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:如果 Android 應用程式使用 IL2CPP,請執行 Firebase CLI crashlytics:symbols:upload 指令,上傳符號檔。

  3. 執行應用程式。應用程式執行後,請觀察裝置記錄,等待 CrashlyticsTester 觸發例外狀況。

    • iOS+:在 Xcode 的底部窗格中查看記錄。

    • Android:在終端機中執行下列指令,即可查看記錄:adb logcat。

  4. 在 Firebase 控制台中,依序前往「DevOps & Engagement」(開發運作與參與度) >「Crashlytics dashboard」(資訊主頁),查看測試當機報告。

    如果重新整理控制台後,五分鐘內仍未看到測試當機事件,請嘗試啟用偵錯記錄檔 (下一節)。

啟用 Crashlytics 的偵錯記錄檔功能

如果 Crashlytics 資訊主頁未顯示測試當機事件,您可以使用 Crashlytics 的偵錯記錄檔功能,追蹤問題。

  1. 在應用程式初始化中加入下列程式碼,啟用 Firebase 的偵錯記錄檔功能:

    Firebase.FirebaseApp.LogLevel = Firebase.LogLevel.Debug;
  2. 強制測試當機。本頁第一節將說明如何執行這項操作。

如果五分鐘後,您仍未在 Firebase 控制台的「DevOps & Engagement」 > 「Crashlytics」資訊主頁中看到這項記錄或測試當機事件,請與 Firebase 支援團隊聯絡,並附上記錄輸出內容副本,以便我們進一步協助您排解問題。

後續步驟