From 72f46e78379287daad62207605f8c61f208593cf Mon Sep 17 00:00:00 2001 From: Abestanis Date: Sat, 25 May 2024 02:33:06 +0200 Subject: [PATCH] Update firebase and run `flutterfire configure` --- .gitattributes | 2 ++ android/app/build.gradle | 23 ++++++------ android/build.gradle | 15 -------- android/settings.gradle | 34 +++++++++++++----- firebase.json | 1 + lib/firebase_options.dart | 64 ++++++++++++++++++++++++++++++++++ lib/main.dart | 73 +++++++++++++++++++++------------------ pubspec.lock | 40 ++++++++++----------- 8 files changed, 163 insertions(+), 89 deletions(-) create mode 100644 firebase.json create mode 100644 lib/firebase_options.dart diff --git a/.gitattributes b/.gitattributes index 2101162e3..dcf2f6160 100644 --- a/.gitattributes +++ b/.gitattributes @@ -4,3 +4,5 @@ pubspec.lock linguist-generated=true .metadata linguist-generated=true # Generated files by the theme_tailor library *.tailor.dart linguist-generated=true +# Generated files by the firebase library +lib/firebase_options.dart linguist-generated=true diff --git a/android/app/build.gradle b/android/app/build.gradle index 434592905..16e1e9f1a 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -1,3 +1,14 @@ +plugins { + id "com.android.application" + // START: FlutterFire Configuration + id 'com.google.gms.google-services' + id 'com.google.firebase.crashlytics' + // END: FlutterFire Configuration + id "kotlin-android" + // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins. + id "dev.flutter.flutter-gradle-plugin" +} + def localProperties = new Properties() def localPropertiesFile = rootProject.file('local.properties') if (localPropertiesFile.exists()) { @@ -21,12 +32,6 @@ if (flutterVersionName == null) { flutterVersionName = '1.0' } -apply plugin: 'com.android.application' -apply plugin: 'kotlin-android' -apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" -apply plugin: 'com.google.gms.google-services' // Google Services plugin -apply plugin: 'com.google.firebase.crashlytics' - def keystoreProperties = new Properties() def keystorePropertiesFile = rootProject.file('key.properties') if (keystorePropertiesFile.exists()) { @@ -80,9 +85,3 @@ android { flutter { source '../..' } - -dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - implementation 'com.google.firebase:firebase-crashlytics:17.4.1' - implementation 'com.google.firebase:firebase-analytics:18.0.3' -} diff --git a/android/build.gradle b/android/build.gradle index 18765e28a..cf9fba7e0 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,18 +1,3 @@ -buildscript { - ext.kotlin_version = '1.6.10' - repositories { - google() - mavenCentral() - } - - dependencies { - classpath 'com.android.tools.build:gradle:7.2.0' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - classpath 'com.google.gms:google-services:4.3.10' // Google Services plugin - classpath 'com.google.firebase:firebase-crashlytics-gradle:2.5.2' - } -} - allprojects { repositories { google() diff --git a/android/settings.gradle b/android/settings.gradle index 44e62bcf0..9c623bb75 100644 --- a/android/settings.gradle +++ b/android/settings.gradle @@ -1,11 +1,29 @@ -include ':app' +pluginManagement { + def flutterSdkPath = { + def properties = new Properties() + file("local.properties").withInputStream { properties.load(it) } + def flutterSdkPath = properties.getProperty("flutter.sdk") + assert flutterSdkPath != null, "flutter.sdk not set in local.properties" + return flutterSdkPath + }() -def localPropertiesFile = new File(rootProject.projectDir, "local.properties") -def properties = new Properties() + includeBuild("$flutterSdkPath/packages/flutter_tools/gradle") -assert localPropertiesFile.exists() -localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) } + repositories { + google() + mavenCentral() + gradlePluginPortal() + } +} -def flutterSdkPath = properties.getProperty("flutter.sdk") -assert flutterSdkPath != null, "flutter.sdk not set in local.properties" -apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle" +plugins { + id "dev.flutter.flutter-plugin-loader" version "1.0.0" + id "com.android.application" version "7.3.0" apply false + // START: FlutterFire Configuration + id "com.google.gms.google-services" version "4.3.15" apply false + id "com.google.firebase.crashlytics" version "2.8.1" apply false + // END: FlutterFire Configuration + id "org.jetbrains.kotlin.android" version "1.9.10" apply false +} + +include ":app" diff --git a/firebase.json b/firebase.json new file mode 100644 index 000000000..a18633835 --- /dev/null +++ b/firebase.json @@ -0,0 +1 @@ +{"flutter":{"platforms":{"android":{"default":{"projectId":"sweyer-def42","appId":"1:574502524315:android:b7be71579f4098be31fd3e","fileOutput":"android/app/google-services.json"}},"dart":{"lib/firebase_options.dart":{"projectId":"sweyer-def42","configurations":{"android":"1:574502524315:android:b7be71579f4098be31fd3e"}}}}}} \ No newline at end of file diff --git a/lib/firebase_options.dart b/lib/firebase_options.dart new file mode 100644 index 000000000..1d72b59de --- /dev/null +++ b/lib/firebase_options.dart @@ -0,0 +1,64 @@ +// File generated by FlutterFire CLI. +// ignore_for_file: lines_longer_than_80_chars, avoid_classes_with_only_static_members +import 'package:firebase_core/firebase_core.dart' show FirebaseOptions; +import 'package:flutter/foundation.dart' + show defaultTargetPlatform, kIsWeb, TargetPlatform; + +/// Default [FirebaseOptions] for use with your Firebase apps. +/// +/// Example: +/// ```dart +/// import 'firebase_options.dart'; +/// // ... +/// await Firebase.initializeApp( +/// options: DefaultFirebaseOptions.currentPlatform, +/// ); +/// ``` +class DefaultFirebaseOptions { + static FirebaseOptions get currentPlatform { + if (kIsWeb) { + throw UnsupportedError( + 'DefaultFirebaseOptions have not been configured for web - ' + 'you can reconfigure this by running the FlutterFire CLI again.', + ); + } + switch (defaultTargetPlatform) { + case TargetPlatform.android: + return android; + case TargetPlatform.iOS: + throw UnsupportedError( + 'DefaultFirebaseOptions have not been configured for ios - ' + 'you can reconfigure this by running the FlutterFire CLI again.', + ); + case TargetPlatform.macOS: + throw UnsupportedError( + 'DefaultFirebaseOptions have not been configured for macos - ' + 'you can reconfigure this by running the FlutterFire CLI again.', + ); + case TargetPlatform.windows: + throw UnsupportedError( + 'DefaultFirebaseOptions have not been configured for windows - ' + 'you can reconfigure this by running the FlutterFire CLI again.', + ); + case TargetPlatform.linux: + throw UnsupportedError( + 'DefaultFirebaseOptions have not been configured for linux - ' + 'you can reconfigure this by running the FlutterFire CLI again.', + ); + default: + throw UnsupportedError( + 'DefaultFirebaseOptions are not supported for this platform.', + ); + } + } + + static const FirebaseOptions android = FirebaseOptions( + apiKey: 'AIzaSyDM1R_dcMdHDIbdJ0aRlNhSIzfN6DTYayg', + appId: '1:574502524315:android:b7be71579f4098be31fd3e', + messagingSenderId: '574502524315', + projectId: 'sweyer-def42', + databaseURL: 'https://sweyer-def42.firebaseio.com', + storageBucket: 'sweyer-def42.appspot.com', + ); + +} \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index 5904907bc..cefba22e6 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -10,6 +10,7 @@ import 'package:sweyer/constants.dart' as constants; import 'package:flutter/material.dart'; import 'package:firebase_core/firebase_core.dart'; import 'package:firebase_crashlytics/firebase_crashlytics.dart'; +import 'firebase_options.dart'; /// Builds up the error report message from the exception and stacktrace. String buildErrorReport(dynamic ex, dynamic stack) { @@ -19,12 +20,14 @@ $ex $stack'''; } -Future reportError(dynamic ex, StackTrace stack) async { +Future reportError(dynamic error, StackTrace stack) async { if (Prefs.isInitialized && Prefs.devMode.get()) { - ShowFunctions.instance.showError(errorDetails: buildErrorReport(ex, stack)); + ShowFunctions.instance.showError( + errorDetails: buildErrorReport(error, stack), + ); } if (Firebase.apps.isNotEmpty) { - await FirebaseCrashlytics.instance.recordError(ex, stack); + await FirebaseCrashlytics.instance.recordError(error, stack, fatal: true); } } @@ -66,38 +69,40 @@ class _WidgetsBindingObserver extends WidgetsBindingObserver { } Future main() async { - runZonedGuarded(() async { - // Disabling automatic system UI adjustment, which causes system nav bar - // color to be reverted to black when the bottom player route is being expanded. - // - // Related to https://github.com/flutter/flutter/issues/40590 - final WidgetsBinding binding = WidgetsFlutterBinding.ensureInitialized(); - binding.renderView.automaticSystemUiAdjustment = false; - await NFPrefs.initialize(); - - await Firebase.initializeApp(); - if (kDebugMode) { - FirebaseFunctions.instance.useFunctionsEmulator('http://localhost/', 5001); - - // Force disable Crashlytics collection while doing every day development. - // Temporarily toggle this to true if you want to test crash reporting in your app. - await FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(false); - } + // Disabling automatic system UI adjustment, which causes system nav bar + // color to be reverted to black when the bottom player route is being expanded. + // + // Related to https://github.com/flutter/flutter/issues/40590 + final WidgetsBinding binding = WidgetsFlutterBinding.ensureInitialized(); + binding.renderView.automaticSystemUiAdjustment = false; + await NFPrefs.initialize(); + + await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform); + if (kDebugMode) { + FirebaseFunctions.instance.useFunctionsEmulator('http://localhost/', 5001); + + // Force disable Crashlytics collection while doing every day development. + // Temporarily toggle this to true if you want to test crash reporting in your app. + await FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(false); + } - Isolate.current.addErrorListener(RawReceivePort((pair) async { - final List errorAndStacktrace = pair; - await reportError(errorAndStacktrace.first, errorAndStacktrace.last); - }).sendPort); - FlutterError.onError = reportFlutterError; - WidgetsBinding.instance.addObserver(_WidgetsBindingObserver()); - - await DeviceInfoControl.instance.init(); - ThemeControl.instance.init(); - ThemeControl.instance.initSystemUi(); - await Permissions.instance.init(); - await ContentControl.instance.init(); - runApp(const ProviderScope(child: App())); - }, reportError); + Isolate.current.addErrorListener(RawReceivePort((pair) async { + final List errorAndStacktrace = pair; + await reportError(errorAndStacktrace.first, errorAndStacktrace.last); + }).sendPort); + FlutterError.onError = reportFlutterError; + PlatformDispatcher.instance.onError = (error, stack) { + reportError(error, stack); + return true; + }; + WidgetsBinding.instance.addObserver(_WidgetsBindingObserver()); + + await DeviceInfoControl.instance.init(); + ThemeControl.instance.init(); + ThemeControl.instance.initSystemUi(); + await Permissions.instance.init(); + await ContentControl.instance.init(); + runApp(const ProviderScope(child: App())); } class App extends StatefulWidget { diff --git a/pubspec.lock b/pubspec.lock index 43a476a78..c935a41d4 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -13,10 +13,10 @@ packages: dependency: transitive description: name: _flutterfire_internals - sha256: "6a0ad72b2bcdb461749e40c01c478212a78db848dfcb2f10f2a461988bc5fb29" + sha256: e4be6711f96d3d4eebe79728897d645b7a5585bbfdd6d534878d202c171266d7 url: "https://pub.dev" source: hosted - version: "1.1.1" + version: "1.3.34" analyzer: dependency: transitive description: @@ -400,66 +400,66 @@ packages: dependency: "direct main" description: name: firebase_analytics - sha256: "2d8f475f79658a8e1865ee8a9e2e8eea70de5e487e3a646d9073dc3d1520d3e8" + sha256: "08f98034f51c8018d08cd56ac51f44c63ab684f85a7b8f0ede92c4acfb23a2bc" url: "https://pub.dev" source: hosted - version: "10.2.1" + version: "10.10.6" firebase_analytics_platform_interface: dependency: transitive description: name: firebase_analytics_platform_interface - sha256: a667807edbcd3f5a6336275a21c8802de8f98f0a91b8c97abb76119b142aa91d + sha256: "4de04e25bd739184eb2cfcd76c2f336c9e03bf65457e1e17d027d65f2344a2df" url: "https://pub.dev" source: hosted - version: "3.4.1" + version: "3.10.7" firebase_analytics_web: dependency: transitive description: name: firebase_analytics_web - sha256: "907285030d59570d7c1a8d721912db990957ab9b87736e50a9457491c16bcffe" + sha256: "77ded8cb214193cc816395625ab8a031539cdd870d667123d1b9d53c7303a82d" url: "https://pub.dev" source: hosted - version: "0.5.2+1" + version: "0.5.7+6" firebase_core: dependency: "direct main" description: name: firebase_core - sha256: "239e4ac688674a7e7b5476fd16b0d8e2b5a453d464f32091af3ce1df4ebb7316" + sha256: "4b5100e2dbc3fe72c2d4241a046d3f01457fe11293283a324f5c52575e3406f8" url: "https://pub.dev" source: hosted - version: "2.10.0" + version: "2.31.1" firebase_core_platform_interface: dependency: transitive description: name: firebase_core_platform_interface - sha256: "0df0a064ab0cad7f8836291ca6f3272edd7b83ad5b3540478ee46a0849d8022b" + sha256: c437ae5d17e6b5cc7981cf6fd458a5db4d12979905f9aafd1fea930428a9fe63 url: "https://pub.dev" source: hosted - version: "4.6.0" + version: "5.0.0" firebase_core_web: dependency: transitive description: name: firebase_core_web - sha256: "347351a8f0518f3343d79a9a0690fa67ad232fc32e2ea270677791949eac792b" + sha256: "43d9e951ac52b87ae9cc38ecdcca1e8fa7b52a1dd26a96085ba41ce5108db8e9" url: "https://pub.dev" source: hosted - version: "2.3.0" + version: "2.17.0" firebase_crashlytics: dependency: "direct main" description: name: firebase_crashlytics - sha256: "02ce958507138d938b4611e3a4910667a44b969b0c20a810bbc97bbf967ba0d7" + sha256: a67dd0c9fe65a3615c9239d189b0c6f4f2a76e17eb945c5a4b688dff8dd21f86 url: "https://pub.dev" source: hosted - version: "3.1.2" + version: "3.5.6" firebase_crashlytics_platform_interface: dependency: transitive description: name: firebase_crashlytics_platform_interface - sha256: b9c7b8498c877a2901ad323fc92c10f672be1597bc82d08f121f6228f321a7e0 + sha256: fc31c00e24ef7b091da8dfd2e7c9dc205f8ca343f68825c15ac8d702e015aec9 url: "https://pub.dev" source: hosted - version: "3.4.1" + version: "3.6.34" fixnum: dependency: transitive description: @@ -958,10 +958,10 @@ packages: dependency: transitive description: name: plugin_platform_interface - sha256: "6a2128648c854906c53fa8e33986fc0247a1116122f9534dd20e3ab9e16a32bc" + sha256: "4820fbfdb9478b1ebae27888254d445073732dae3d6ea81f0b7e06d5dedc3f02" url: "https://pub.dev" source: hosted - version: "2.1.4" + version: "2.1.8" pointycastle: dependency: transitive description: