התחלה מהירה זו מתארת כיצד להגדיר את Firebase Crashlytics באפליקציה שלך עם Firebase Crashlytics SDK כדי שתוכל לקבל דוחות קריסה מקיפים במסוף Firebase.עם Crashlytics לאנדרואיד, אתה מקבל דוחות על קריסות, שגיאות לא קטלניות ושגיאות "אפליקציה לא מגיבה" (ANR).
הגדרת Crashlytics דורשת משימות הן במסוף Firebase והן ב-IDE שלך (כמו הוספת קובץ תצורה של Firebase ו-Crashlytics SDK). כדי לסיים את ההגדרה, תצטרך לאלץ קריסת בדיקה כדי לשלוח את דוח הקריסה הראשון שלך ל-Firebase.
לפני שאתה מתחיל
אם עדיין לא עשית זאת, הוסף את Firebase לפרויקט Android שלך. אם אין לך אפליקציית אנדרואיד, תוכל להוריד אפליקציה לדוגמה .
מומלץ : כדי לקבל תכונות כמו משתמשים ללא קריסות, יומני פירורי לחם והתראות מהירות, עליך להפעיל את Google Analytics בפרויקט Firebase שלך.
אם בפרויקט Firebase הקיים שלך לא מופעל Google Analytics, תוכל להפעיל את Google Analytics מהכרטיסייה אינטגרציות שלך > הגדרות פרויקט במסוף Firebase.
אם אתה יוצר פרויקט Firebase חדש, הפעל את Google Analytics במהלך תהליך העבודה של יצירת הפרויקט.
שלב 1 : הוסף את Firebase Crashlytics SDK לאפליקציה שלך
באמצעות Firebase Android BoM , הכריז על התלות של ספריית Crashlytics Android בקובץ Gradle של המודול (ברמת האפליקציה) (בדרך כללapp/build.gradle
).לחוויה מיטבית עם Crashlytics, אנו ממליצים להפעיל את Google Analytics בפרויקט Firebase שלך ולהוסיף את Firebase SDK עבור Google Analytics לאפליקציה שלך.
Java
dependencies { // Import the BoM for the Firebase platform implementation platform('com.google.firebase:firebase-bom:30.2.0') // Declare the dependencies for the Crashlytics and Analytics libraries // When using the BoM, you don't specify versions in Firebase library dependencies implementation 'com.google.firebase:firebase-crashlytics' implementation 'com.google.firebase:firebase-analytics' }
על ידי שימוש ב- Firebase Android BoM , האפליקציה שלך תמיד תשתמש בגרסאות תואמות של ספריות Firebase Android.
(אלטרנטיבי) הכרזה על תלות בספריית Firebase מבלי להשתמש ב-BoM
אם תבחר שלא להשתמש ב-Firebase BoM, עליך לציין כל גרסת ספריית Firebase בשורת התלות שלה.
שים לב שאם אתה משתמש במספר ספריות Firebase באפליקציה שלך, אנו ממליצים בחום להשתמש ב-BoM לניהול גרסאות ספרייה, מה שמבטיח שכל הגרסאות תואמות.
dependencies { // Declare the dependencies for the Crashlytics and Analytics libraries // When NOT using the BoM, you must specify versions in Firebase library dependencies implementation 'com.google.firebase:firebase-crashlytics:18.2.11' implementation 'com.google.firebase:firebase-analytics:21.0.0' }
Kotlin+KTX
dependencies { // Import the BoM for the Firebase platform implementation platform('com.google.firebase:firebase-bom:30.2.0') // Declare the dependencies for the Crashlytics and Analytics libraries // When using the BoM, you don't specify versions in Firebase library dependencies implementation 'com.google.firebase:firebase-crashlytics-ktx' implementation 'com.google.firebase:firebase-analytics-ktx' }
על ידי שימוש ב- Firebase Android BoM , האפליקציה שלך תמיד תשתמש בגרסאות תואמות של ספריות Firebase Android.
(אלטרנטיבי) הכרזה על תלות בספריית Firebase מבלי להשתמש ב-BoM
אם תבחר שלא להשתמש ב-Firebase BoM, עליך לציין כל גרסת ספריית Firebase בשורת התלות שלה.
שים לב שאם אתה משתמש במספר ספריות Firebase באפליקציה שלך, אנו ממליצים בחום להשתמש ב-BoM לניהול גרסאות ספרייה, מה שמבטיח שכל הגרסאות תואמות.
dependencies { // Declare the dependencies for the Crashlytics and Analytics libraries // When NOT using the BoM, you must specify versions in Firebase library dependencies implementation 'com.google.firebase:firebase-crashlytics-ktx:18.2.11' implementation 'com.google.firebase:firebase-analytics-ktx:21.0.0' }
שלב 2 : הוסף את הפלאגין Firebase Crashlytics לאפליקציה שלך
בקובץ
build.gradle
ברמת הפרויקט, הוסף את הפלאגין Crashlytics Gradle כתלות ב-buildscript.buildscript { repositories { // Check that you have Google's Maven repository (if not, add it). google() } dependencies { // ... // Check that you have the Google services Gradle plugin v4.3.2 or later // (if not, add it). classpath 'com.google.gms:google-services:4.3.13' // Add the Crashlytics Gradle plugin classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.1' } } allprojects { repositories { // Check that you have Google's Maven repository (if not, add it). google() } }
בקובץ
build.gradle
ברמת האפליקציה, החל את הפלאגין Crashlytics Gradle:apply plugin: 'com.android.application' apply plugin: 'com.google.gms.google-services' // Google services Gradle plugin // Apply the Crashlytics Gradle plugin apply plugin: 'com.google.firebase.crashlytics'
שלב 3 : כפה קריסת בדיקה כדי לסיים את ההגדרה
כדי לסיים את הגדרת Crashlytics ולראות נתונים ראשוניים בלוח המחוונים של Crashlytics של קונסולת Firebase, עליך לאלץ קריסת מבחן.
הוסף קוד לאפליקציה שלך שבו תוכל להשתמש כדי לאלץ קריסת מבחן.
אתה יכול להשתמש בקוד הבא ב-
MainActivity
של האפליקציה שלך כדי להוסיף לחצן לאפליקציה שלך, שכאשר לוחצים עליו, גורם לקריסה. הכפתור מסומן "קריסת בדיקה".Java
Button crashButton = new Button(this); crashButton.setText("Test Crash"); crashButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { throw new RuntimeException("Test Crash"); // Force a crash } }); addContentView(crashButton, new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
Kotlin+KTX
val crashButton = Button(this) crashButton.text = "Test Crash" crashButton.setOnClickListener { throw RuntimeException("Test Crash") // Force a crash } addContentView(crashButton, ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT))
בנה והפעל את האפליקציה שלך.
כפה את קריסת הבדיקה כדי לשלוח את דוח הקריסה הראשון של האפליקציה שלך:
פתח את האפליקציה שלך ממכשיר הבדיקה או האמולטור שלך.
באפליקציה שלך, לחץ על כפתור "Test Crash" שהוספת באמצעות הקוד שלמעלה.
לאחר שהאפליקציה שלך קורסת, הפעל אותה מחדש כדי שהאפליקציה תוכל לשלוח את דוח הקריסה ל-Firebase.
עבור אל לוח המחוונים של Crashlytics של מסוף Firebase כדי לראות את קריסת המבחן שלך.
אם רענן את המסוף ואתה עדיין לא רואה את קריסת הבדיקה לאחר חמש דקות, הפעל רישום באגים כדי לראות אם האפליקציה שלך שולחת דוחות קריסה.
וזה הכל! Crashlytics עוקבת כעת אחר האפליקציה שלך לאיתור קריסות, שגיאות לא קטלניות ומקרי ANR. בקר במרכז השליטה של Crashlytics כדי להציג ולחקור את כל הדוחות והסטטיסטיקות שלך.
הצעדים הבאים
- התאם אישית את הגדרת דוחות הקריסה שלך על ידי הוספת דיווחי הסכמה, יומנים, מפתחות ומעקב אחר שגיאות לא קטלניות.
- שלב עם Google Play כך שתוכל לסנן את דוחות הקריסה של אפליקציית Android שלך לפי מסלול Google Play ישירות במרכז השליטה של Crashlytics. זה מאפשר לך למקד טוב יותר את לוח המחוונים שלך בבנייה ספציפית.
- הצג עקבות מחסנית וסטטיסטיקות קריסות ישירות לצד הקוד שלך באמצעות חלון ' תובנות איכות האפליקציה ' ב-Android Studio. באמצעות כלי זה, אינך צריך לדלג קדימה ואחורה בין לוח המחוונים של Crashlytics ל-IDE כדי להתחיל לטפל בבעיות מובילות.
- קבל גישה לתכונה זו בגרסה האחרונה של Canary של Android Studio - Electric Eel | 2022.1.1 .
- למידע נוסף על השימוש בתכונה זו בתיעוד התכונות החדשות עבור Android Studio.
- מכיוון שמדובר בתכונה קנרית, נשמח לשמוע ממך! אם יש לך משוב או נתקלת בבעיות כלשהן, אנא הגש דוח באג .
,
התחלה מהירה זו מתארת כיצד להגדיר את Firebase Crashlytics באפליקציה שלך עם Firebase Crashlytics SDK כדי שתוכל לקבל דוחות קריסה מקיפים במסוף Firebase.עם Crashlytics לאנדרואיד, אתה מקבל דוחות על קריסות, שגיאות לא קטלניות ושגיאות "אפליקציה לא מגיבה" (ANR).
הגדרת Crashlytics דורשת משימות הן במסוף Firebase והן ב-IDE שלך (כמו הוספת קובץ תצורה של Firebase ו-Crashlytics SDK). כדי לסיים את ההגדרה, תצטרך לאלץ קריסת בדיקה כדי לשלוח את דוח הקריסה הראשון שלך ל-Firebase.
לפני שאתה מתחיל
אם עדיין לא עשית זאת, הוסף את Firebase לפרויקט Android שלך. אם אין לך אפליקציית אנדרואיד, תוכל להוריד אפליקציה לדוגמה .
מומלץ : כדי לקבל תכונות כמו משתמשים ללא קריסות, יומני פירורי לחם והתראות מהירות, עליך להפעיל את Google Analytics בפרויקט Firebase שלך.
אם בפרויקט Firebase הקיים שלך לא מופעל Google Analytics, תוכל להפעיל את Google Analytics מהכרטיסייה אינטגרציות שלך > הגדרות פרויקט במסוף Firebase.
אם אתה יוצר פרויקט Firebase חדש, הפעל את Google Analytics במהלך תהליך העבודה של יצירת הפרויקט.
שלב 1 : הוסף את Firebase Crashlytics SDK לאפליקציה שלך
באמצעות Firebase Android BoM , הכריז על התלות של ספריית Crashlytics Android בקובץ Gradle של המודול (ברמת האפליקציה) (בדרך כללapp/build.gradle
).לחוויה מיטבית עם Crashlytics, אנו ממליצים להפעיל את Google Analytics בפרויקט Firebase שלך ולהוסיף את Firebase SDK עבור Google Analytics לאפליקציה שלך.
Java
dependencies { // Import the BoM for the Firebase platform implementation platform('com.google.firebase:firebase-bom:30.2.0') // Declare the dependencies for the Crashlytics and Analytics libraries // When using the BoM, you don't specify versions in Firebase library dependencies implementation 'com.google.firebase:firebase-crashlytics' implementation 'com.google.firebase:firebase-analytics' }
על ידי שימוש ב- Firebase Android BoM , האפליקציה שלך תמיד תשתמש בגרסאות תואמות של ספריות Firebase Android.
(אלטרנטיבי) הכרזה על תלות בספריית Firebase מבלי להשתמש ב-BoM
אם תבחר שלא להשתמש ב-Firebase BoM, עליך לציין כל גרסת ספריית Firebase בשורת התלות שלה.
שים לב שאם אתה משתמש במספר ספריות Firebase באפליקציה שלך, אנו ממליצים בחום להשתמש ב-BoM לניהול גרסאות ספרייה, מה שמבטיח שכל הגרסאות תואמות.
dependencies { // Declare the dependencies for the Crashlytics and Analytics libraries // When NOT using the BoM, you must specify versions in Firebase library dependencies implementation 'com.google.firebase:firebase-crashlytics:18.2.11' implementation 'com.google.firebase:firebase-analytics:21.0.0' }
Kotlin+KTX
dependencies { // Import the BoM for the Firebase platform implementation platform('com.google.firebase:firebase-bom:30.2.0') // Declare the dependencies for the Crashlytics and Analytics libraries // When using the BoM, you don't specify versions in Firebase library dependencies implementation 'com.google.firebase:firebase-crashlytics-ktx' implementation 'com.google.firebase:firebase-analytics-ktx' }
על ידי שימוש ב- Firebase Android BoM , האפליקציה שלך תמיד תשתמש בגרסאות תואמות של ספריות Firebase Android.
(אלטרנטיבי) הכרזה על תלות בספריית Firebase מבלי להשתמש ב-BoM
אם תבחר שלא להשתמש ב-Firebase BoM, עליך לציין כל גרסת ספריית Firebase בשורת התלות שלה.
שים לב שאם אתה משתמש במספר ספריות Firebase באפליקציה שלך, אנו ממליצים בחום להשתמש ב-BoM לניהול גרסאות ספרייה, מה שמבטיח שכל הגרסאות תואמות.
dependencies { // Declare the dependencies for the Crashlytics and Analytics libraries // When NOT using the BoM, you must specify versions in Firebase library dependencies implementation 'com.google.firebase:firebase-crashlytics-ktx:18.2.11' implementation 'com.google.firebase:firebase-analytics-ktx:21.0.0' }
Step 2 : Add the Firebase Crashlytics plugin to your app
In your project-level
build.gradle
file, add the Crashlytics Gradle plugin as a buildscript dependency.buildscript { repositories { // Check that you have Google's Maven repository (if not, add it). google() } dependencies { // ... // Check that you have the Google services Gradle plugin v4.3.2 or later // (if not, add it). classpath 'com.google.gms:google-services:4.3.13' // Add the Crashlytics Gradle plugin classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.1' } } allprojects { repositories { // Check that you have Google's Maven repository (if not, add it). google() } }
In your app-level
build.gradle
file, apply the Crashlytics Gradle plugin:apply plugin: 'com.android.application' apply plugin: 'com.google.gms.google-services' // Google services Gradle plugin // Apply the Crashlytics Gradle plugin apply plugin: 'com.google.firebase.crashlytics'
Step 3 : Force a test crash to finish setup
To finish setting up Crashlytics and see initial data in the Crashlytics dashboard of the Firebase console, you need to force a test crash.
Add code to your app that you can use to force a test crash.
You can use the following code in your app's
MainActivity
to add a button to your app that, when pressed, causes a crash. The button is labeled "Test Crash".Java
Button crashButton = new Button(this); crashButton.setText("Test Crash"); crashButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { throw new RuntimeException("Test Crash"); // Force a crash } }); addContentView(crashButton, new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
Kotlin+KTX
val crashButton = Button(this) crashButton.text = "Test Crash" crashButton.setOnClickListener { throw RuntimeException("Test Crash") // Force a crash } addContentView(crashButton, ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT))
Build and run your app.
Force the test crash in order to send your app's first crash report:
Open your app from your test device or emulator.
In your app, press the "Test Crash" button that you added using the code above.
After your app crashes, restart it so that your app can send the crash report to Firebase.
Go to the Crashlytics dashboard of the Firebase console to see your test crash.
If you've refreshed the console and you're still not seeing the test crash after five minutes, enable debug logging to see if your app is sending crash reports.
And that's it! Crashlytics is now monitoring your app for crashes, non-fatal errors, and ANRs. Visit the Crashlytics dashboard to view and investigate all your reports and statistics.
Next steps
- Customize your crash report setup by adding opt-in reporting, logs, keys, and tracking of non-fatal errors.
- Integrate with Google Play so that you can filter your Android app's crash reports by Google Play track directly in the Crashlytics dashboard. This allows you to better focus your dashboard on specific builds.
- View stack traces and crash statistics directly alongside your code with the App Quality Insights window in Android Studio. Using this tool, you don't need to jump back and forth between the Crashlytics dashboard and the IDE to start addressing top issues.
- Get access to this feature in the latest Canary version of Android Studio - Electric Eel | 2022.1.1 .
- Learn more about using this feature in the New Features documentation for Android Studio.
- Since this is a canary feature, we'd like to hear from you! If you have any feedback or encounter any issues, please file a bug report .