برنامه نویسی

Firebase Crashlytics – انجمن DEV

Summarize this content to 400 words in Persian Lang
بیایید نگاهی به نحوه تنظیم مدیریت خرابی برنامه با Firebase با استفاده از Flutter بیندازیم.

0. سفارش راه اندازی پروژه Firebase

یک پروژه Firebase ایجاد کنید:

در کنسول Firebase، یک پروژه جدید ایجاد کنید یا یک پروژه موجود را انتخاب کنید.

ثبت اپلیکیشن:

در کنسول Firebase، به «تنظیمات پروژه» بروید و روی «افزودن برنامه» کلیک کنید.
نام بسته برنامه Flutter شما (applicationId).
نام بسته (Get SHA1 Fingerprint) برنامه Flutter خود را وارد کنید.

اثر انگشت گواهی SHA-1 را دریافت کنید:

در پنجره کنسول در اندروید استودیو

$ ./gradlew signingReport

google-services.json دانلود:

google-services.json فایل را دانلود کنید.
در پروژه Flutter خود فایل کنید. android/app آن را در یک دایرکتوری کپی کنید.

1*. firebase cli را نصب و پیکربندی کنید*

firebase_options.dart را ایجاد کنید. بعداً خطاهای مربوط به aipkey و چندین خطای installizeApp برطرف خواهند شد.

$ curl -sL https://firebase.tools | bash

$ firebase login

$ firebase projects:list

$ dart pub global activate flutterfire_cli

=================================================================
.zshrc or .bashrc 추가 후 flutterfire 실행
export PATH=”$PATH”:”$HOME/.pub-cache/bin”
==================================================================
$ flutterfire configure

وارد حالت تمام صفحه شوید

از حالت تمام صفحه خارج شوید

2. تنظیمات پروژه فلوتر

pubspec.yaml ویرایش فایل:

بسته های مرتبط با Firebase pubspec.yaml به فایل اضافه کنید.

dependencies:
flutter:
sdk: flutter
firebase_core: ^3.1.1 # Firebase 초기화 패키지
firebase_crashlytics: ^4.0.2 # Crashlytics 패키지

– `firebase_core`는 Firebase 서비스 초기화를 담당하고,
`firebase_crashlytics`는 앱 충돌 관리를 위해 필요합니다.

وارد حالت تمام صفحه شوید

از حالت تمام صفحه خارج شوید

تنظیمات پروژه اندروید:

پروژه فلاتر android/build.gradle فایل را باز کنید،
buildscript بلوک و مسیر کلاس افزونه های مربوط به Firebase را اضافه کنید.

buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath ‘com.google.gms:google-services:4.4.2’
classpath ‘com.google.firebase:firebase-crashlytics-gradle:2.7.1’
}
}

allprojects {
repositories {
google()
mavenCentral()
}
}

rootProject.buildDir = “../build”
subprojects {
project.buildDir = “${rootProject.buildDir}/${project.name}”
}
subprojects {
project.evaluationDependsOn(“:app”)
}

tasks.register(“clean”, Delete) {
delete rootProject.buildDir
}

– Google Services 플러그인의 버전(`com.google.gms:google-services`)
– Firebase Crashlytics 플러그인의 버전
(`com.google.firebase:firebase-crashlytics-gradle`)을 설정합니다.

وارد حالت تمام صفحه شوید

از حالت تمام صفحه خارج شوید

سطح برنامه build.gradle تصحیح:

پروژه فلاتر android/app/build.gradle فایل را باز کنید و افزونه Firebase Crashlytics را اضافه کنید.

plugins {
id “com.android.application”
id “kotlin-android”
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
id “dev.flutter.flutter-gradle-plugin”
// firbase Crashlytics
id “‘com.google.gms.google-services'”
id “com.google.firebase.crashlytics”
}

dependencies { // Firbase Crashlytics
implementation(platform(“com.google.firebase:firebase-bom:33.1.1”))
// implementation ‘com.google.firebase:firebase-analytics-ktx’
implementation ‘com.google.firebase:firebase-crashlytics-ktx’
}

“com.google.gms.google-services”و “com.google.firebase.crashlytics”و
“com.google.firebase:firebase-bom:33.1.1” (مدیریت وابستگی) برای فعال کردن خدمات Firebase و Crashlytics اضافه کنید.

پایان (تست)

“”تصادف رخ داد” دکمه را فشار دهید تا بررسی کنید که آیا در زمان واقعی کار می کند یا خیر

import ‘dart:async’;
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/foundation.dart’;

// The entry point of the application
Futurevoid> main() async {
//———————–
await Firebase.initializeApp();
FlutterError.onError = (errorDetails) {
FirebaseCrashlytics.instance.recordFlutterFatalError(errorDetails);
};
// Pass all uncaught asynchronous errors that aren’t handled by the Flutter framework to Crashlytics
PlatformDispatcher.instance.onError = (error, stack) {
FirebaseCrashlytics.instance.recordError(error, stack, fatal: true);
return true;
};

//————————

// Runs the main application widget
runApp(const WhereIsKaaba());
}

// Main application widget
class WhereIsKaaba extends StatelessWidget {
const WhereIsKaaba({super.key});

// This widget is the root of your application.
@override
Widget build(BuildContext context) {
// Define the light text theme based on Material3
final TextTheme lightTextTheme =
ThemeData.light(useMaterial3: true).textTheme;
// Define the dark text theme based on Material3
final TextTheme darkTextTheme =
ThemeData.dark(useMaterial3: true).textTheme;

// Create a custom material theme for the light theme
final CustomMaterialTheme lightCustomMaterialTheme =
CustomMaterialTheme(lightTextTheme);
// Create a custom material theme for the dark theme
final CustomMaterialTheme darkCustomMaterialTheme =
CustomMaterialTheme(darkTextTheme);

return MaterialApp(
debugShowCheckedModeBanner: false,
// Localization delegates for internationalization support
localizationsDelegates: const [
S.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
// Supported locales for the application
supportedLocales: S.delegate.supportedLocales,
//////////////////////////////////////////////////
// Title of the application
title: ‘Where is Kaaba.?’,
// Light theme configuration
theme: lightCustomMaterialTheme.light(),
// Dark theme configuration
darkTheme: darkCustomMaterialTheme.dark(),
// Home widget of the application
home: Semantics(
label: ‘Main Screen with navigation tabs’,
child: Center(
child: ElevatedButton(
onPressed: () {
// 강제로 예외를 발생시켜 Crashlytics 로그를 테스트합니다.
throw Exception(“테스트 예외”);
},
child: const Text(“크래시 발생”),
),
),
),
);
}
}

وارد حالت تمام صفحه شوید

از حالت تمام صفحه خارج شوید

بیایید نگاهی به نحوه تنظیم مدیریت خرابی برنامه با Firebase با استفاده از Flutter بیندازیم.

0. سفارش راه اندازی پروژه Firebase

  1. یک پروژه Firebase ایجاد کنید:

    • در کنسول Firebase، یک پروژه جدید ایجاد کنید یا یک پروژه موجود را انتخاب کنید.

  2. ثبت اپلیکیشن:

    • در کنسول Firebase، به «تنظیمات پروژه» بروید و روی «افزودن برنامه» کلیک کنید.
    • نام بسته برنامه Flutter شما (applicationId).
    • نام بسته (Get SHA1 Fingerprint) برنامه Flutter خود را وارد کنید.
  3. اثر انگشت گواهی SHA-1 را دریافت کنید:

    • در پنجره کنسول در اندروید استودیو
    $ ./gradlew signingReport
    
  4. google-services.json دانلود:

    • google-services.json فایل را دانلود کنید.
    • در پروژه Flutter خود فایل کنید. android/app آن را در یک دایرکتوری کپی کنید.

1*. firebase cli را نصب و پیکربندی کنید*

firebase_options.dart را ایجاد کنید. بعداً خطاهای مربوط به aipkey و چندین خطای installizeApp برطرف خواهند شد.

$ curl -sL https://firebase.tools | bash 

$ firebase login

$ firebase projects:list

$ dart pub global activate flutterfire_cli 

=================================================================
.zshrc or .bashrc 추가 후 flutterfire 실행
export PATH="$PATH":"$HOME/.pub-cache/bin"
==================================================================
$ flutterfire configure

وارد حالت تمام صفحه شوید

از حالت تمام صفحه خارج شوید

2. تنظیمات پروژه فلوتر

  1. pubspec.yaml ویرایش فایل:

    • بسته های مرتبط با Firebase pubspec.yaml به فایل اضافه کنید.
    dependencies:
      flutter:
        sdk: flutter
      firebase_core: ^3.1.1  # Firebase 초기화 패키지
      firebase_crashlytics: ^4.0.2  # Crashlytics 패키지
    
    
- `firebase_core`는 Firebase 서비스 초기화를 담당하고, 
`firebase_crashlytics`는 앱 충돌 관리를 위해 필요합니다.
وارد حالت تمام صفحه شوید

از حالت تمام صفحه خارج شوید

  1. تنظیمات پروژه اندروید:

    • پروژه فلاتر android/build.gradle فایل را باز کنید،
      buildscript بلوک و مسیر کلاس افزونه های مربوط به Firebase را اضافه کنید.
    buildscript {
        repositories {
            google()
            mavenCentral()
        }
        dependencies {
            classpath 'com.google.gms:google-services:4.4.2'
            classpath 'com.google.firebase:firebase-crashlytics-gradle:2.7.1'
        }
    }
    
    allprojects {
        repositories {
            google()
            mavenCentral()
        }
    }
    
    rootProject.buildDir = "../build"
    subprojects {
        project.buildDir = "${rootProject.buildDir}/${project.name}"
    }
    subprojects {
        project.evaluationDependsOn(":app")
    }
    
    tasks.register("clean", Delete) {
        delete rootProject.buildDir
    }
    
    
- Google Services 플러그인의 버전(`com.google.gms:google-services`)
- Firebase Crashlytics 플러그인의 버전
(`com.google.firebase:firebase-crashlytics-gradle`)을 설정합니다.
وارد حالت تمام صفحه شوید

از حالت تمام صفحه خارج شوید

  1. سطح برنامه build.gradle تصحیح:

    • پروژه فلاتر android/app/build.gradle فایل را باز کنید و افزونه Firebase Crashlytics را اضافه کنید.
    plugins {
        id "com.android.application"
        id "kotlin-android"
        // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
        id "dev.flutter.flutter-gradle-plugin"
        // firbase Crashlytics
        id "'com.google.gms.google-services'"
        id "com.google.firebase.crashlytics"
    }
    
    dependencies { // Firbase Crashlytics
        implementation(platform("com.google.firebase:firebase-bom:33.1.1"))
        // implementation 'com.google.firebase:firebase-analytics-ktx'
        implementation 'com.google.firebase:firebase-crashlytics-ktx'
    }
    
  • "com.google.gms.google-services"و "com.google.firebase.crashlytics"و
    "com.google.firebase:firebase-bom:33.1.1" (مدیریت وابستگی) برای فعال کردن خدمات Firebase و Crashlytics اضافه کنید.

پایان (تست)

  • “تصادف رخ داد” دکمه را فشار دهید تا بررسی کنید که آیا در زمان واقعی کار می کند یا خیر
import 'dart:async';
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/foundation.dart';

// The entry point of the application
Futurevoid> main() async {
//-----------------------
  await Firebase.initializeApp();
  FlutterError.onError = (errorDetails) {
    FirebaseCrashlytics.instance.recordFlutterFatalError(errorDetails);
  };
  // Pass all uncaught asynchronous errors that aren't handled by the Flutter framework to Crashlytics
  PlatformDispatcher.instance.onError = (error, stack) {
    FirebaseCrashlytics.instance.recordError(error, stack, fatal: true);
    return true;
  };

//------------------------

  // Runs the main application widget
  runApp(const WhereIsKaaba());
}

// Main application widget
class WhereIsKaaba extends StatelessWidget {
  const WhereIsKaaba({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    // Define the light text theme based on Material3
    final TextTheme lightTextTheme =
        ThemeData.light(useMaterial3: true).textTheme;
    // Define the dark text theme based on Material3
    final TextTheme darkTextTheme =
        ThemeData.dark(useMaterial3: true).textTheme;

    // Create a custom material theme for the light theme
    final CustomMaterialTheme lightCustomMaterialTheme =
        CustomMaterialTheme(lightTextTheme);
    // Create a custom material theme for the dark theme
    final CustomMaterialTheme darkCustomMaterialTheme =
        CustomMaterialTheme(darkTextTheme);

    return MaterialApp(
      debugShowCheckedModeBanner: false,
      // Localization delegates for internationalization support
      localizationsDelegates: const [
        S.delegate,
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      // Supported locales for the application
      supportedLocales: S.delegate.supportedLocales,
      //////////////////////////////////////////////////
      // Title of the application
      title: 'Where is Kaaba.?',
      // Light theme configuration
      theme: lightCustomMaterialTheme.light(),
      // Dark theme configuration
      darkTheme: darkCustomMaterialTheme.dark(),
      // Home widget of the application
      home: Semantics(
        label: 'Main Screen with navigation tabs',
        child: Center(
          child: ElevatedButton(
            onPressed: () {
             // 강제로 예외를 발생시켜 Crashlytics 로그를 테스트합니다.
              throw Exception("테스트 예외");
            },
            child: const Text("크래시 발생"),
          ),
        ),
      ),
    );
  }
}

وارد حالت تمام صفحه شوید

از حالت تمام صفحه خارج شوید

image

نوشته های مشابه

دیدگاهتان را بنویسید

نشانی ایمیل شما منتشر نخواهد شد. بخش‌های موردنیاز علامت‌گذاری شده‌اند *

دکمه بازگشت به بالا