From b750417415f7c36f9b69d1f2f87d04397282fbf2 Mon Sep 17 00:00:00 2001 From: Yegor Vialov Date: Tue, 11 Feb 2020 12:06:19 +0000 Subject: [PATCH] Replace Sentry with Crashlytics --- android/app/build.gradle | 1 + android/build.gradle | 7 +++++++ lib/main.dart | 22 ++++++++-------------- lib/pages/main.page.dart | 1 + pubspec.yaml | 2 +- 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index 7afc434..fbc3a66 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -84,4 +84,5 @@ dependencies { androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' } +apply plugin: 'io.fabric' apply plugin: 'com.google.gms.google-services' diff --git a/android/build.gradle b/android/build.gradle index 305f967..4ed845e 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -2,11 +2,15 @@ buildscript { repositories { google() jcenter() + maven { + url 'https://maven.fabric.io/public' + } } dependencies { classpath 'com.android.tools.build:gradle:3.3.2' classpath 'com.google.gms:google-services:4.3.3' + classpath 'io.fabric.tools:gradle:1.26.1' } } @@ -14,6 +18,9 @@ allprojects { repositories { google() jcenter() + maven { + url 'https://maven.fabric.io/public' + } } } diff --git a/lib/main.dart b/lib/main.dart index 16c99bf..574593a 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -27,7 +27,7 @@ import 'plugins/spoiler_card.dart'; import 'package:workmanager/workmanager.dart' as workManager; import 'package:geolocator/geolocator.dart'; import 'package:battery/battery.dart'; -import 'package:sentry/sentry.dart'; +import 'package:firebase_crashlytics/firebase_crashlytics.dart'; import 'package:flutter_webview_plugin/flutter_webview_plugin.dart'; import 'utils/logger.dart'; @@ -137,7 +137,7 @@ part 'entities/media_player/widgets/media_player_progress_bar.widget.dart'; part 'pages/whats_new.page.dart'; EventBus eventBus = new EventBus(); -final SentryClient _sentry = SentryClient(dsn: "https://03ef364745cc4c23a60ddbc874c69925@sentry.io/1836118"); +//final SentryClient _sentry = SentryClient(dsn: "https://03ef364745cc4c23a60ddbc874c69925@sentry.io/1836118"); final FirebaseMessaging _firebaseMessaging = FirebaseMessaging(); FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = new FlutterLocalNotificationsPlugin(); const String appName = "HA Client"; @@ -150,27 +150,21 @@ Future _reportError(dynamic error, dynamic stackTrace) async { if (Logger.isInDebugMode) { Logger.e('Caught error: $error'); Logger.p(stackTrace); - return; - } else { - Logger.e('Caught error: $error. Reporting to Senrty.'); - // Send the Exception and Stacktrace to Sentry in Production mode. - _sentry.captureException( - exception: error, - stackTrace: stackTrace, - ); } + Crashlytics.instance.recordError(error, stackTrace); + } void main() async { + //TODO remove when configured + Crashlytics.instance.enableInDevMode = true; + FlutterError.onError = (FlutterErrorDetails details) { Logger.e(" Caut Flutter runtime error: ${details.exception}"); if (Logger.isInDebugMode) { FlutterError.dumpErrorToConsole(details); - } else { - // In production mode, report to the application zone to report to - // Sentry. - Zone.current.handleUncaughtError(details.exception, details.stack); } + Crashlytics.instance.recordFlutterError(details); }; runZoned(() { diff --git a/lib/pages/main.page.dart b/lib/pages/main.page.dart index fb0343b..55224c5 100644 --- a/lib/pages/main.page.dart +++ b/lib/pages/main.page.dart @@ -131,6 +131,7 @@ class _MainPageState extends State with WidgetsBindingObserver, Ticker } }); eventBus.fire(RefreshDataFinishedEvent()); + throw new Exception("There is an error thrown specifically for Crashlitycs reporting test!"); } @override diff --git a/pubspec.yaml b/pubspec.yaml index 4a1e692..afaf4f8 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -29,7 +29,7 @@ dependencies: geolocator: ^5.2.1 workmanager: ^0.2.0 battery: ^0.3.1+7 - sentry: ^2.3.1 + firebase_crashlytics: ^0.1.2+5 dev_dependencies: