From 6232ad555a23e68db7b06cd9f34ec3e4b4114f22 Mon Sep 17 00:00:00 2001 From: Vadim <44135514+vodemn@users.noreply.github.com> Date: Wed, 3 May 2023 12:45:10 +0200 Subject: [PATCH] ML-51 Integrate Crashlytics (#52) * added crashlytics * added firebase_options to CD * Version bump * added firebase_options to CI * timeout --- .github/workflows/cd_dev.yml | 14 +++++++------- .github/workflows/cd_prod.yml | 14 +++++++------- .github/workflows/ci.yml | 12 +++++++++--- analysis_options.yaml | 4 +--- android/app/build.gradle | 1 + android/build.gradle | 1 + lib/firebase.dart | 14 ++++++++++++++ lib/main_prod.dart | 3 +++ pubspec.yaml | 4 +++- 9 files changed, 46 insertions(+), 21 deletions(-) create mode 100644 lib/firebase.dart diff --git a/.github/workflows/cd_dev.yml b/.github/workflows/cd_dev.yml index 07cee3f..0a8a466 100644 --- a/.github/workflows/cd_dev.yml +++ b/.github/workflows/cd_dev.yml @@ -59,13 +59,13 @@ jobs: echo -n "$GOOGLE_SERVICES_JSON_ANDROID" | base64 --decode --output $GOOGLE_SERVICES_JSON_ANDROID_PATH cp $GOOGLE_SERVICES_JSON_ANDROID_PATH ./android/app - # - name: Restore lib/firebase_options.dart - # env: - # KEYSTORE: ${{ secrets.FIREBASE_OPTIONS }} - # run: | - # FIREBASE_OPTIONS_PATH=$RUNNER_TEMP/firebase_options.dart - # echo -n "$FIREBASE_OPTIONS" | base64 --decode --output $FIREBASE_OPTIONS_PATH - # cp $FIREBASE_OPTIONS_PATH ./lib + - name: Restore firebase_options.dart + env: + FIREBASE_OPTIONS: ${{ secrets.FIREBASE_OPTIONS }} + run: | + FIREBASE_OPTIONS_PATH=$RUNNER_TEMP/firebase_options.dart + echo -n "$FIREBASE_OPTIONS" | base64 --decode --output $FIREBASE_OPTIONS_PATH + cp $FIREBASE_OPTIONS_PATH ./lib - name: Install Flutter uses: subosito/flutter-action@v2 diff --git a/.github/workflows/cd_prod.yml b/.github/workflows/cd_prod.yml index ce64feb..594be1d 100644 --- a/.github/workflows/cd_prod.yml +++ b/.github/workflows/cd_prod.yml @@ -50,13 +50,13 @@ jobs: echo -n "$GOOGLE_SERVICES_JSON_ANDROID" | base64 --decode --output $GOOGLE_SERVICES_JSON_ANDROID_PATH cp $GOOGLE_SERVICES_JSON_ANDROID_PATH ./android/app - # - name: Restore firebase_options.dart - # env: - # FIREBASE_OPTIONS: ${{ secrets.FIREBASE_OPTIONS }} - # run: | - # FIREBASE_OPTIONS_PATH=$RUNNER_TEMP/firebase_options.dart - # echo -n "$FIREBASE_OPTIONS" | base64 --decode --output $FIREBASE_OPTIONS_PATH - # cp $FIREBASE_OPTIONS_PATH ./lib + - name: Restore firebase_options.dart + env: + FIREBASE_OPTIONS: ${{ secrets.FIREBASE_OPTIONS }} + run: | + FIREBASE_OPTIONS_PATH=$RUNNER_TEMP/firebase_options.dart + echo -n "$FIREBASE_OPTIONS" | base64 --decode --output $FIREBASE_OPTIONS_PATH + cp $FIREBASE_OPTIONS_PATH ./lib - name: Install Flutter uses: subosito/flutter-action@v2 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 40703d4..28c3401 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ on: jobs: build: runs-on: macos-11 - timeout-minutes: 5 + timeout-minutes: 10 steps: - uses: shaunco/ssh-agent@git-repo-mapping @@ -41,7 +41,13 @@ jobs: - name: Generate intl run: flutter pub run intl_utils:generate + - name: Restore firebase_options.dart + env: + FIREBASE_OPTIONS: ${{ secrets.FIREBASE_OPTIONS }} + run: | + FIREBASE_OPTIONS_PATH=$RUNNER_TEMP/firebase_options.dart + echo -n "$FIREBASE_OPTIONS" | base64 --decode --output $FIREBASE_OPTIONS_PATH + cp $FIREBASE_OPTIONS_PATH ./lib + - name: Analyze project source run: flutter analyze lib --fatal-infos -# - name: Run tests -# run: flutter test diff --git a/analysis_options.yaml b/analysis_options.yaml index fb80863..a3be6b8 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,3 +1 @@ -include: package:flutter_lints/flutter.yaml -analyzer: - exclude: [lib/main_prod.dart] \ No newline at end of file +include: package:flutter_lints/flutter.yaml \ No newline at end of file diff --git a/android/app/build.gradle b/android/app/build.gradle index 5f24621..57d4449 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -29,6 +29,7 @@ if (keystorePropertiesFile.exists()) { apply plugin: 'com.android.application' apply plugin: 'com.google.gms.google-services' +apply plugin: 'com.google.firebase.crashlytics' apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" diff --git a/android/build.gradle b/android/build.gradle index bb34f99..e0630bc 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -8,6 +8,7 @@ buildscript { dependencies { classpath 'com.android.tools.build:gradle:7.1.2' classpath 'com.google.gms:google-services:4.3.10' + classpath 'com.google.firebase:firebase-crashlytics-gradle:2.8.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } diff --git a/lib/firebase.dart b/lib/firebase.dart new file mode 100644 index 0000000..ca2407a --- /dev/null +++ b/lib/firebase.dart @@ -0,0 +1,14 @@ +import 'package:firebase_core/firebase_core.dart'; +import 'package:firebase_crashlytics/firebase_crashlytics.dart'; +import 'package:flutter/foundation.dart'; + +import 'firebase_options.dart'; + +Future initializeFirebase() async { + await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform); + FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterFatalError; + PlatformDispatcher.instance.onError = (error, stack) { + FirebaseCrashlytics.instance.recordError(error, stack, fatal: true); + return true; + }; +} diff --git a/lib/main_prod.dart b/lib/main_prod.dart index cb6e570..627f016 100644 --- a/lib/main_prod.dart +++ b/lib/main_prod.dart @@ -2,8 +2,11 @@ import 'package:flutter/material.dart'; import 'package:lightmeter/environment.dart'; import 'application.dart'; +import 'firebase.dart'; Future main() async { WidgetsFlutterBinding.ensureInitialized(); + await initializeFirebase(); + runApp(const Application(Environment.prod())); } diff --git a/pubspec.yaml b/pubspec.yaml index a9ac6eb..d013ac1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: lightmeter description: A new Flutter project. publish_to: "none" -version: 0.9.1+16 +version: 0.9.2+17 environment: sdk: ">=2.18.0 <3.0.0" @@ -11,6 +11,8 @@ dependencies: camera: 0.10.0+4 exif: 3.1.2 dynamic_color: 1.5.4 + firebase_core: 2.10.0 + firebase_crashlytics: 3.1.2 flutter: sdk: flutter flutter_bloc: 8.1.1