測試 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 資訊主頁,查看測試當機情況。

重新整理控制台後,如果 5 分鐘後仍未看到測試當機情況,請嘗試啟用偵錯記錄功能 (下一節)。

啟用 Crashlytics 的偵錯記錄功能

如果 Crashlytics 資訊主頁未顯示測試當機情形,您可以使用 Crashlytics 的偵錯記錄功能來找出問題。

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

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

如果五分鐘後仍未看到 Firebase 的記錄,或 Firebase 的 Crashlytics 資訊主頁中出現測試當機問題,請與 Firebase 支援聯絡,並提供記錄輸出的副本,以便我們進一步協助您排解問題。

後續步驟