From adb1262c7943453d0e59d674e006581b2a891cce Mon Sep 17 00:00:00 2001 From: Raul Date: Sun, 26 Jun 2022 17:24:08 -0500 Subject: [PATCH] Firebase Crashlytics --- .gitignore | 1 - android/app/build.gradle | 3 ++- android/app/google-services.json | 22 +++++++--------------- android/build.gradle | 2 ++ ios/firebase_app_id_file.json | 7 +++++++ lib/main.dart | 27 ++++++++++++++++++--------- lib/screens/app/app.dart | 3 +++ pubspec.yaml | 1 + 8 files changed, 40 insertions(+), 26 deletions(-) create mode 100644 ios/firebase_app_id_file.json diff --git a/.gitignore b/.gitignore index 2b34d9451..aead01bca 100644 --- a/.gitignore +++ b/.gitignore @@ -79,7 +79,6 @@ !/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages .vscode - .env* secret_config.json pubspec\.lock diff --git a/android/app/build.gradle b/android/app/build.gradle index b088905d1..6ee3f4364 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -84,4 +84,5 @@ dependencies { androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' } -apply plugin: 'com.google.gms.google-services' \ No newline at end of file +apply plugin: 'com.google.gms.google-services' +apply plugin: 'com.google.firebase.crashlytics' \ No newline at end of file diff --git a/android/app/google-services.json b/android/app/google-services.json index 60c336944..87830eae3 100644 --- a/android/app/google-services.json +++ b/android/app/google-services.json @@ -8,20 +8,12 @@ "client": [ { "client_info": { - "mobilesdk_app_id": "1:366914936426:android:7d2393ccb8b3bdda1a3413", + "mobilesdk_app_id": "1:366914936426:android:978896cb9d8996661a3413", "android_client_info": { - "package_name": "com.joinseeds.seedswallet" + "package_name": "com.joinseeds.parq" } }, "oauth_client": [ - { - "client_id": "366914936426-kn6vumn468dl6vc1rdp9ircp6v9ehufg.apps.googleusercontent.com", - "client_type": 1, - "android_info": { - "package_name": "com.joinseeds.seedswallet", - "certificate_hash": "ada86e0a7e0067084ed872e08681b2104aaf5270" - } - }, { "client_id": "366914936426-92ud91kd7hqj98to79aospg00m3f3to7.apps.googleusercontent.com", "client_type": 3 @@ -53,18 +45,18 @@ }, { "client_info": { - "mobilesdk_app_id": "1:366914936426:android:389b18d13a862a531a3413", + "mobilesdk_app_id": "1:366914936426:android:7d2393ccb8b3bdda1a3413", "android_client_info": { - "package_name": "com.joinseeds.wallet" + "package_name": "com.joinseeds.seedswallet" } }, "oauth_client": [ { - "client_id": "366914936426-k4i8n24qb9eu1ug0cqs0rcfvc3pq1fh3.apps.googleusercontent.com", + "client_id": "366914936426-kn6vumn468dl6vc1rdp9ircp6v9ehufg.apps.googleusercontent.com", "client_type": 1, "android_info": { - "package_name": "com.joinseeds.wallet", - "certificate_hash": "1d4a3d87c78e5d83f8b7c7fb5240f10fe072132f" + "package_name": "com.joinseeds.seedswallet", + "certificate_hash": "ada86e0a7e0067084ed872e08681b2104aaf5270" } }, { diff --git a/android/build.gradle b/android/build.gradle index 22a38f43c..557a0b2fb 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -7,6 +7,8 @@ buildscript { dependencies { classpath 'com.google.gms:google-services:4.3.3' + + classpath 'com.google.firebase:firebase-crashlytics-gradle:2.8.1' classpath 'com.android.tools.build:gradle:4.2.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } diff --git a/ios/firebase_app_id_file.json b/ios/firebase_app_id_file.json new file mode 100644 index 000000000..7ea88b467 --- /dev/null +++ b/ios/firebase_app_id_file.json @@ -0,0 +1,7 @@ +{ + "file_generated_by": "FlutterFire CLI", + "purpose": "FirebaseAppID & ProjectID for this Firebase app in this directory", + "GOOGLE_APP_ID": "1:366914936426:ios:75e7ba91678551811a3413", + "FIREBASE_PROJECT_ID": "seeds-77371", + "GCM_SENDER_ID": "366914936426" +} \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index 801f9485b..03cf0b457 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,6 +1,8 @@ import 'dart:async'; +import 'dart:isolate'; import 'package:firebase_core/firebase_core.dart'; +import 'package:firebase_crashlytics/firebase_crashlytics.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -15,7 +17,20 @@ import 'package:seeds/domain-shared/bloc_observer.dart'; import 'package:seeds/seeds_app.dart'; Future main() async { - // Zone to handle asynchronous errors (Dart). + // To catch errors that happen outside of the Flutter context + // add an error listener on the current Isolate: + Isolate.current.setErrorsFatal(false); + Isolate.current.addErrorListener(RawReceivePort((pair) async { + final List errorAndStacktrace = pair; + await FirebaseCrashlytics.instance.recordError( + errorAndStacktrace.first, + errorAndStacktrace.last, + fatal: true, + ); + }).sendPort); + + // If we're using zones, instrumenting the zone’s error handler will catch errors + // that aren't caught by the Flutter framework (i.e. in a button’s onPressed handler) // for details: https://docs.flutter.dev/testing/errors await runZonedGuarded(() async { WidgetsFlutterBinding.ensureInitialized(); @@ -29,11 +44,7 @@ Future main() async { await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]); // Called whenever the Flutter framework catches an error. - FlutterError.onError = (details) async { - FlutterError.presentError(details); - // TODO(Raul): use FirebaseCrashlytics or whatever - //await FirebaseCrashlytics.instance.recordFlutterError(details); - }; + FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterFatalError; if (kDebugMode) { /// Bloc logs only in debug (for better performance in release) @@ -41,7 +52,5 @@ Future main() async { } else { runApp(const SeedsApp()); } - }, (error, stackTrace) async { - //await FirebaseCrashlytics.instance.recordError(error, stack); - }); + }, (error, stack) => FirebaseCrashlytics.instance.recordError(error, stack, fatal: true)); } diff --git a/lib/screens/app/app.dart b/lib/screens/app/app.dart index 021f70940..3acae56c7 100644 --- a/lib/screens/app/app.dart +++ b/lib/screens/app/app.dart @@ -1,3 +1,4 @@ +import 'package:firebase_crashlytics/firebase_crashlytics.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_svg/flutter_svg.dart'; @@ -5,6 +6,7 @@ import 'package:seeds/blocs/deeplink/viewmodels/deeplink_bloc.dart'; import 'package:seeds/blocs/rates/viewmodels/rates_bloc.dart'; import 'package:seeds/components/full_page_loading_indicator.dart'; import 'package:seeds/components/notification_badge.dart'; +import 'package:seeds/datasource/local/settings_storage.dart'; import 'package:seeds/design/app_colors.dart'; import 'package:seeds/design/app_theme.dart'; import 'package:seeds/domain-shared/event_bus/event_bus.dart'; @@ -61,6 +63,7 @@ class _AppState extends State with WidgetsBindingObserver { @override void initState() { super.initState(); + FirebaseCrashlytics.instance.setCustomKey('user', settingsStorage.accountName); _appBloc = AppBloc(BlocProvider.of(context))..add(const OnAppMounted()); _connectionNotifier = ConnectionNotifier()..discoverEndpoints(); BlocProvider.of(context).add(const OnFetchRates()); diff --git a/pubspec.yaml b/pubspec.yaml index b40590a4b..81dd2d97a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -62,6 +62,7 @@ dependencies: geolocator: ^8.2.0 geocoding: ^2.0.2 permission_handler: ^9.2.0 + firebase_crashlytics: ^2.8.2 dev_dependencies: flutter_test: