前往主控台

Firebase Crashlytics API changes for Unity

With the release of Firebase Crashlytics for Unity, the Firebase team is bringing the functionality that developers depend upon with Fabric to Firebase. This move presents an opportunity to make some small changes to ensure that the Firebase Crashlytics APIs are more intuitive and developer-friendly.

Developers already using the Fabric Crashlytics SDK might need to make some minor changes to their code when upgrading to Firebase Crashlytics. This guide provides details on the specific changes to the API, the reason for the change, and helpful suggestions where workarounds are required.

Fabric.Crashlytics is now Firebase.Crashlytics

We've changed our namespace from Fabric to Firebase.

Fabric

using Fabric.Crashlytics;

Firebase

using Firebase.Crashlytics;

RecordCustomException is now LogException

Log custom non-fatal exceptions that were caught and handled.

Fabric

Crashlytics.RecordCustomException(string name, string reason, StackTrace stackTrace);
Crashlytics.RecordCustomException(string name, string reason, string stackTraceString);

Firebase

Crashlytics.LogException(Exception ex);

Reason for change

This function is most often used to log an instance of an Exception. Rather than requiring you to extract the "name", "reason", and "stackTrace" manually (which results in superfluous code), you can now provide the instance of the Exception and Firebase Crashlytics will extract the information that it needs.

Workaround

If you were leveraging these parameters in a way other than just pulling the information directly off of an exception, you can still accomplish the previous behavior by creating your own Exception subclass with the custom metadata in its description.

SetKeyValue is now SetCustomKey

Set any key/value pair to send along with your crash report. Re-setting the same key will update the value.

Fabric

Crashlytics.SetKeyValue(string key, string value);

Firebase

Crashlytics.SetCustomKey(string key, string value);

Reason for change

This method is being renamed to make its behavior more clear and to improve consistency with other Firebase APIs.

SetUserIdentifier is now SetUserId

Set a user identifier to help understand which user experienced a crash.

Fabric

Crashlytics.SetUserIdentifier(string identifier);

Firebase

Crashlytics.SetUserId(string identifier);

Reason for change

This method is being renamed to improve consistency with other Firebase APIs. As a bonus, it's shorter; who doesn't love shaving off key strokes?

SetUserEmail and SetUserName are removed

Previously, you were allowed to set a name or email associated with a crash using explicit methods. These will no longer be explicitly defined.

Fabric

Crashlytics.SetUserEmail(string email);
Crashlytics.SetUserName(string name);

Reason for change

Google strives to protect customer data, and part of that effort is designing APIs that do the same for developer tooling. These user-specific APIs have been removed to encourage the use of generated and non-personally identifying methods for discerning which user was affected by a crash.

Workaround

To specify which user experienced a crash, the preferred method is to use SetUserId. However, if this is not a tenable solution, the same functionality can be accomplished using SetCustomKey.

Crash and ThrowNonFatal are removed

Previously, Crashlytics provided two utility methods to throw exceptions for testing purposes. These will not be included in Firebase Crashlytics.

Fabric

Crashlytics.Crash();
Crashlytics.ThrowNonFatal();

Reason for change

Crashlytics for Unity runs in many different environments, and many different kinds of crashes can occur. These methods did not clearly specify whether the resulting crashes occurred in C# or in the underlying platform-specific native SDK.

Workaround