Flutter Firebase Crashlytics reports stack trace as Java class files and not as Dart files - firebase

I have integrated Flutter Crashlytics in our app, but it is reporting crashes stack trace in Java class files and not in Dart files. So it is difficult to infer what is the file and line number where this issue occurred in the flutter codebase.
Here is an example of one such crash report from Firebase Crashltytics of an Uncaught exception:
Non-fatal Exception: java.lang.Exception: NoSuchMethodError: The method 'markNeedsBuild' was called on null.
Receiver: null
Tried calling: markNeedsBuild()
at State.setState(State.java:1168)
at _ArgonButtonState.initState.<fn>(initState.java:107)
at AnimationLocalStatusListenersMixin.notifyStatusListeners(AnimationLocalStatusListenersMixin.java:193)
at AnimationController._checkStatusChanged(AnimationController.java:773)
at AnimationController._tick(AnimationController.java:789)
at Ticker._tick(Ticker.java:237)
at SchedulerBinding._invokeFrameCallback(SchedulerBinding.java:1102)
at SchedulerBinding.handleBeginFrame.<fn>(handleBeginFrame.java:1017)
at SchedulerBinding.handleBeginFrame(SchedulerBinding.java:1015)
at SchedulerBinding._handleBeginFrame(SchedulerBinding.java:949)
Here is how Crashlytics is initialized:
// Pass all uncaught errors from the framework to Crashlytics.
FlutterError.onError = Crashlytics.instance.recordFlutterError;
runZoned(() {
runApp(AppMain(homeWidget));
}, onError: Crashlytics.instance.recordError);
I am reporting caught exceptions as such:
Crashlytics.instance.recordError(error, stack);
How can I configure Crashlytics to report stack trace in dart? Does Crashlytics show erroneous file names and line numbers for Dart source code?

Todd from Crashlytics. This is a known behavior and we are looking into possible options moving forward. Kotlin users will see a similar behavior.

I would suggest to move on to Sentry.
I am doing it for my app now. And while just testing it, I can say that sentry is much better than Crashlytics!

Related

Flutter navigate HERE SDK crash

I am using the Flutter navigate SDK (The latest 4.12.7.0)
I'm getting this crash randomly. any guidance on how to fix or avoid?
34
[log] [WARN ] hf::navigation::lane_assistance - Could not fetch lanes: hf::navigation::ocm::Requested data could not be found in the map
libc++abi: terminating with uncaught exception of type std::bad_variant_access: bad_variant_access

Flutter Crashlytics - No Crash log for non-fatal flutter error

We are using firebase_crashlytics: ^0.4.0+1 in a flutter app. Within the runApp() we are starting to listen to errors and crashes just like mentioned in the documentation.
runZonedGuarded(() {
runApp(
..
}, (error, stackTrace) {
FirebaseCrashlytics.instance.recordError(error, stackTrace);
});
In general crashes are reported, but not for these type of crashes EXCEPTION CAUGHT BY WIDGETS LIBRARY.
In some circumstances objects might be null, but instead of getting a crash reported to the firebase crashlytics dashboard, nothing happens. User only receive a grey screen and that is it.
Therefore we only are notified if a user reports these errors, but we receive no logs.
Is this a non-fatal error and we should be using recordFlutterError method?
BTW, this is being called when the error is thrown:
Function originalOnError = FlutterError.onError;
FlutterError.onError = (FlutterErrorDetails errorDetails) async {
await FirebaseCrashlytics.instance.recordFlutterError(errorDetails);
// Forward to original handler.
originalOnError(errorDetails);
Even the method originalOnError(errorDetails) is called the error is not recorded in the firebase crashlytics dashboard.
How can we make these non-fatal errors also be reported?
The logging has been done by firebase crashlytics. The default filter in the firebase console dashboard was set to crashes. Removing the filter and we can see all reported errors, crashes, non-fatal errors.
Thanks to this stackoverflow post

How to crash Flutter App for Android and iOS (to test Firebase Crashlytics)?

I want to test out crash report using Firebase Crashlytics in my Flutter App. I need to Fatal crash my flutter app for both Android and iOS programmatically. Any idea?
If you have the flutter_crashlytics plugin, you can test it using
FirebaseCrashlytics.instance.crash();
You should be able to throw a Dart exception by doing this anywhere in your Flutter app:
throw Exception("This is a crash!");
Or by using an arbitrary object:
throw "This is a crash!";
You can find more info about dart exceptions in the language tour and if you want, you can create your own custom Exception type as explained in this SO answer
integrate firebase_crashlytics
Crashlytics.instance.crash();
using firebase_crashlytics plugin
FirebaseCrashlytics.instance.crash();
You should enable crashlytics
void main() async{
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
if (kDebugMode) {
FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(true);//disable false
}else{
FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(true);
}
You can crash you Flutter app by many ways:
throw(Exception('Hello Crashlytics')); like in #Xavi Rigau's answer
List list;
list.add("add");
Like #Paresh Mangukiya does.
3.
final a = [12];
print(a[1]);
But there is 2 IMPORTANT thing you should consider:
You should run your app in release mode, for example with the command flutter run --release
In Crashlytycs console, by default shown only fatal crashes. The crashes above are non-fatal crashes. So, you should clear the filter to see all crash types. (Filter can be filtered in crashlytics dashboard by clicking (x) button near filter). More on this you can read from this SO answer
Check this out . This is from the official documentation. https://firebase.flutter.dev/docs/crashlytics/usage
Once your configuration is proper according to documentation for crashlytics, FirebaseCrashlytics.instance.crash(); will crash the app.

Firebase Strictmode resource leak

After converting from Crashlytics via Fabric to Crashlytics via Firebase, I started seeing the below call stack in debug runs where StrictMode is enabled looking for resource leaks.
StrictMode is in use with this code, only on debug builds:
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
.detectLeakedClosableObjects()
.penaltyLog()
.build());
I'm using this versions of Fabric's gradle tools in project-level gradle:
classpath "io.fabric.tools:gradle:1.27.0"
and these versions of Firebase and Crashlytics in module-level gradle:
implementation "com.google.firebase:firebase-core:16.0.7"
implementation "com.crashlytics.sdk.android:crashlytics:2.9.8"
During initialization, the Firebase instrumentation kicks off a background thread that is doing settings calls using okhttp. When it does, StrictMode causes this call stack to pop:
W/CrashlyticsCore: Received null settings, skipping report submission!
D/StrictMode: StrictMode policy violation: android.os.strictmode.LeakedClosableViolation: A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
at android.os.StrictMode$AndroidCloseGuardReporter.report(StrictMode.java:1786)
at dalvik.system.CloseGuard.warnIfOpen(CloseGuard.java:264)
at java.util.zip.Inflater.finalize(Inflater.java:398)
at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:250)
at java.lang.Daemons$FinalizerDaemon.runInternal(Daemons.java:237)
at java.lang.Daemons$Daemon.run(Daemons.java:103)
at java.lang.Thread.run(Thread.java:764)
Caused by: java.lang.Throwable: Explicit termination method 'end' not called
at dalvik.system.CloseGuard.open(CloseGuard.java:221)
at java.util.zip.Inflater.<init>(Inflater.java:114)
at com.android.okhttp.okio.GzipSource.<init>(GzipSource.java:62)
at com.android.okhttp.internal.http.HttpEngine.unzip(HttpEngine.java:473)
at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:648)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:471)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:407)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:538)
at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getResponseCode(DelegatingHttpsURLConnection.java:105)
at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:26)
at io.fabric.sdk.android.services.network.HttpRequest.code(HttpRequest.java:1357)
at io.fabric.sdk.android.services.settings.DefaultSettingsSpiCall.handleResponse(DefaultSettingsSpiCall.java:104)
at io.fabric.sdk.android.services.settings.DefaultSettingsSpiCall.invoke(DefaultSettingsSpiCall.java:88)
at io.fabric.sdk.android.services.settings.DefaultSettingsController.loadSettingsData(DefaultSettingsController.java:90)
at io.fabric.sdk.android.services.settings.DefaultSettingsController.loadSettingsData(DefaultSettingsController.java:67)
at io.fabric.sdk.android.services.settings.Settings.loadSettingsData(Settings.java:153)
at io.fabric.sdk.android.Onboarding.retrieveSettingsData(Onboarding.java:126)
at io.fabric.sdk.android.Onboarding.doInBackground(Onboarding.java:99)
at io.fabric.sdk.android.Onboarding.doInBackground(Onboarding.java:45)
at io.fabric.sdk.android.InitializationTask.doInBackground(InitializationTask.java:63)
at io.fabric.sdk.android.InitializationTask.doInBackground(InitializationTask.java:28)
at io.fabric.sdk.android.services.concurrency.AsyncTask$2.call(AsyncTask.java:311)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:458)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764) 
D/FA: Event not sent since app measurement is disabled
I see this happening on pretty much every debug run of my app, during the initial activity startup in the app. However support claims they don't see this.
Does anyone know what conditions cause Fabric to kick off this onboarding/settings thread?
I've seen similar StrictMode call stacks in these other posts. I can't tell if this leak is in Fabric code, or in the okhttp library they are using. Here are links to similar cases where people are seeing what looks to me like the same underlying resource leak:
StrictMode penalising for Firebase Ads
Crashlytics with StrictMode enabled (detect all) gives "untagged socket detected"
https://github.com/cloudant/sync-android/issues/577

Better exception call stack in Firebase Crashlytics for React Native app

I' receiving some crash reports in my Firebase Crashlytics dashboard. However, the report only shows native code call stacks, and JS stack is minimized and un-readable. For example:
Fatal Exception: com.facebook.react.common.JavascriptException: undefined is not a function (evaluating 'r[n]()'), stack:
<unknown>#284:210
value#36:1363
value#23:3582
<unknown>#23:1067
value#23:3009
value#23:1039
at com.facebook.react.modules.core.ExceptionsManagerModule.showOrThrowError(ExceptionsManagerModule.java:54)
at com.facebook.react.modules.core.ExceptionsManagerModule.reportFatalException(ExceptionsManagerModule.java:38)
at java.lang.reflect.Method.invoke(Method.java)
at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:160)
at com.facebook.react.bridge.queue.NativeRunnable.run(NativeRunnable.java)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:29)
at android.os.Looper.loop(Looper.java:164)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:192)
at java.lang.Thread.run(Thread.java:764)
The only thing I can get from the above report is that the JS code is trying to invoke an undefined object, but it's hard to locate where exactly the issue is at.
Is it possible to submit a symbol file or mapping file of some kind, so that this report can be more useful to help me see which function is having the problem?
Thank you.

Resources