測試您的 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 支持並提供日誌輸出的副本,以便我們可以幫助您進一步排除故障。

下一步