flutter firebase_crashlytics 사용

Gooak·2024년 2월 22일

회사앱에 비정상 크래시를 알기위해 firebase_crashytics를 사용하였다
이번에는 내 개인엡에다가도 한번 넣어보려한다

firebase_crashlytics: ^3.4.15

flutter pub add 해주고

Android

android>build.gradle

dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.2' // 파이어베이스 크래시 추가}

android>app>build.gradle

apply plugin: 'com.google.firebase.crashlytics' //파이어베이스 크래시 추가

IOS

처음에 cocoaPods pod 버전 오류가 떠서
Podfile.lock를 지우고 다시 설치하였다

rm -rf Podfile.lock
pod repo update
arch -x86_64 pod install --repo-update

메인코드
main.dart

void main() async {
  configLoading();
  runZonedGuarded(
    () async {
      WidgetsFlutterBinding.ensureInitialized();
      await Firebase.initializeApp(
        options: DefaultFirebaseOptions.currentPlatform,
      );
      runApp(const MyApp());
    },
    (error, stack) => FirebaseCrashlytics.instance.recordError(
      error,
      stack,
      fatal: true,
    ),
  );
}

이렇게 하여 오류 스택을 전송합니다
처음엔 runZoneGuraded 안에 runApp만 넣었었는데 그랬었다가

The following assertion was thrown during runApp:
Zone mismatch.
The Flutter bindings were initialized in a different zone than is now being used. This will likely cause confusion and bugs as any zone-specific configuration will inconsistently use the configuration of the original binding initialization zone or this zone based on hard-to-predict factors such as which zone was active when a particular callback was set.
It is important to use the same zone when calling `ensureInitialized` on the binding as when calling `runApp` later.
To make this warning fatal, set BindingBase.debugZoneErrorsAreFatal to true before the bindings are initialized (i.e. as the first statement in `void main() { }`).

이러한 오류가 떠 위 코드처럼 작성하였다.

강제 종료 테스트로

FirebaseCrashlytics.instance.crash();

를 사용하면 된다.


정상적으로 잘 작동하는걸 볼 수 있다.

profile
구악

0개의 댓글