测试您的 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 Editor 插件会自动配置您的 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. 强制造成测试崩溃。本页第一部分介绍了如何执行此操作。

如果您在 5 分钟后未在 Firebase 控制台的 Crashlytics 信息中心内看到来自 Firebase 的日志或测试崩溃报告,请联系 Firebase 支持团队并提供您的日志输出副本,以便我们进一步排查问题。

后续步骤