測試 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. 前往下列網址的 Crashlytics 資訊主頁: Firebase 控制台,查看測試當機情形。

重新整理控制台後,如未發現測試當機 請在五分鐘後嘗試啟用偵錯記錄功能 (下一節)。

啟用 Crashlytics 的偵錯記錄功能

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

  1. 將下列程式碼加入 應用程式初始化:

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

如果在 Crashlytics 中找不到 Firebase 記錄或測試當機問題 以及 Firebase 控制台的資訊主頁 Firebase 支援,提供副本: 執行這些動作,以便我們進一步協助您排解問題。

後續步驟