Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to see Dart code stack trace instead of Java code stack trace in Crashlytics/Flutter (Android)

We are using the firebase_crashlytics plugin for Flutter to get error reports in Crashlytics. Unfortunately for Android, only the non-fatal issues show a proper Dart code stack trace. The fatal issues only show Java code stack trace which makes them very hard to debug.

Is there any way to get proper Dart code stack traces for fatal issues as well?

like image 756
Mark Avatar asked Jun 06 '20 13:06

Mark


People also ask

What is StackTrace in Dart?

A StackTrace is intended to convey information to the user about the call sequence that triggered an exception. These objects are created by the runtime, it is not possible to create them programmatically.

What is a stack trace in Java?

These frames represent a moment during an application’s execution. A stack frame is information about a method or function that your code called. So the Java stack trace is a list of frames that starts at the current method and extends to when the program started. Sometimes there’s confusion between a stack and the Stack.

How do I run a stack trace in Android Studio?

From the Analyze menu, click Analyze Stack Trace . Paste the stack trace text into the Analyze Stack Trace window and click OK . Android Studio opens a new <Stacktrace> tab with the stack trace you pasted under the Run window.

How to read a stack trace for an arithmetic exception?

To read this stack trace, start at the top with the Exception's type - ArithmeticException and message The denominator must not be zero.

How do I get the stack trace of a thread?

Get a Stack Trace Using the Thread Class We can obtain a stack trace from a thread by calling the getStackTrace () method on the Thread instance. It returns an array of StackTraceElement, from which details about stack frames of the thread can be found.


1 Answers

I added this lines to my main.dart to get the Dart StackTrace:

FlutterError.onError = (error) => flutterErrorHandler(error);

runZonedGuarded<Future<void>>(
    () async => runApp(
      YourAppWidget(),
    ),
    (error, strack) async {
      debugPrint(error.toString());
      // Whenever an error occurs, call the `reportCrash`
      // to send Dart errors to Crashlytics
      Crashlytics.instance.recordError(error, strack);
    },
  );
void flutterErrorHandler(FlutterErrorDetails details) {
  FlutterError.dumpErrorToConsole(details);

  // Report to the application zone to report to Crashlytics.
  Zone.current.handleUncaughtError(details.exception, details.stack);
}

For more details see: https://pub.dev/packages/firebase_crashlytics

like image 146
Nils Reichardt Avatar answered Oct 16 '22 23:10

Nils Reichardt