Join us for Firebase Summit on November 10, 2021. Tune in to learn how Firebase can help you accelerate app development, release with confidence, and scale with ease. Register

Test your Crashlytics implementation

Force a crash to test your implementation

  1. Find an existing GameObject, then add to it the following script. This script will cause a test crash a few seconds after you run your app.

    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 non-fatal errors 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. Build and run your app.

  3. Once your app is running, watch the device log and wait for the exception to trigger from the CrashlyticsTester.

    • iOS: View logs in the bottom pane of Xcode.

    • Android: View logs by running the following command in the terminal: adb logcat.

  4. When you see the exception in your device log, restart your app so that it can send the crash report to Firebase.

  5. Go to the Crashlytics dashboard of the Firebase console to see your test crash.

If you've refreshed the console and you're still not seeing the test crash after five minutes, try enabling debug logging (next section).

Enable debug logging for Crashlytics

If you don't see your test crash in the Crashlytics dashboard, you can use debug logging for Crashlytics to help track down the problem.

  1. Enable debug logging for Firebase by adding the following code to your app initialization:

    Firebase.FirebaseApp.LogLevel = Firebase.LogLevel.Debug;
  2. Force a test crash. The first section on this page describes how to do this.

If you don't see logs from Firebase or your test crash in the Crashlytics dashboard of the Firebase console after five minutes, reach out to Firebase Support with a copy of your log output so that we can help you troubleshoot further.

Next steps