במהלך הפיתוח והבדיקה של האפליקציה, כדאי להשבית את התכונה Performance Monitoring
לדוגמה, על ידי השבתה של Performance Monitoring במהלך תהליך ה-build של האפליקציה, תוכלו:
משביתים פונקציות מסוימות של Performance Monitoring (כמו אלה שסופקו על ידי הפלאגין Performance Monitoring Gradle) בגרסאות ה-build לניפוי באגים, אבל מפעילים מחדש את הפונקציות בגרסאות ה-build לפריסה.
השבתה של Performance Monitoring בזמן פיתוח האפליקציה, אבל מתן הרשאה לאפליקציה להפעיל אותה מחדש בזמן ריצה.
להשבית את Performance Monitoring בזמן פיתוח האפליקציה ולא לאפשר לאפליקציה: להפעיל אותו מחדש בזמן הריצה.
אפשר גם לפתח את האפליקציה כשהתכונה Performance Monitoring מופעלת, אבל יש להשתמש ב-Firebase Remote Config כדי לתת לך גמישות שמאפשרת להשבית (ולהפעיל מחדש) את Performance Monitoring באפליקציה בסביבת הייצור. ב- באפשרות הזו, אפשר אפילו להגדיר את האפליקציה כך שמשתמשים יוכלו להביע הסכמה או לבטל את הסכמתם באמצעות Performance Monitoring.
השבתת Performance Monitoring במהלך תהליך ה-build של האפליקציה
אפשר להשבית את Performance Monitoring במהלך תהליך ה-build על ידי השבתה של הפלאגין Performance Monitoring ל-Gradle ו/או על ידי השבתה של ספריית Android Performance Monitoring.
במהלך הפיתוח וניפוי הבאגים, השבתת הפלאגין מועילה מכיוון אינסטרומנטציה על ידי הפלאגין יכולות לשפר את זמן ה-build. אבל כדאי גם להשאיר את להפעיל את הספרייה כדי שעדיין תוכלו לראות את נתוני הביצועים של מעקב אחר הפעלת האפליקציה, הצגת האפליקציה ברקע ורקע של אפליקציות וגם כל אחד מעקבי קוד בהתאמה אישית באפליקציה.
השבתת הפלאגין Gradle של Performance Monitoring
אפשר להשבית את הפלאגין Performance Monitoring על ידי הוספת instrumentationEnabled
באמצעות האפשרויות הבאות:
נכס תוסף — משבית את הפלאגין עבור וריאנט build ספציפי בזמן הידור (compile)
Project Property — השבתת הפלאגין עבור כל הווריאנטים של ה-build בזמן הידור
השבתת הפלאגין דרך סימון של נכס תוסף
באמצעות סימון נכס תוספים, ניתן להשבית את הפלאגין Performance Monitoring לווריאנט build ספציפי בזמן הידור (compile).
בקובץ Gradle ברמת השורש (ברמת הפרויקט) (
<project>/build.gradle.kts
או<project>/build.gradle
), צריך לוודא התלות של Android Gradle Plugin מוגדרת כגרסה 3.4.0 ואילך.בגרסאות קודמות של הפלאגין של Android Gradle, עדיין תוכלו להשבית את הפלאגין Performance Monitoring לגרסה ספציפית של build, אבל הזמן שהפלאגין ייצור במהלך ה-build לא יוסר לגמרי מהגרסה הזו.
מוסיפים את הדגל הבא לקובץ המודול (ברמת האפליקציה) של Gradle (בדרך כלל)
<project>/<app-module>/build.gradle.kts
או<project>/<app-module>/build.gradle
), לאחר מכן צריך להגדיר אותו ל-false
כדי להשבית את הפלאגין Performance Monitoring.Kotlin
import com.google.firebase.perf.plugin.FirebasePerfExtension // ... android { // ... buildTypes { getByName("debug") { configure<FirebasePerfExtension> { // Set this flag to 'false' to disable @AddTrace annotation processing and // automatic monitoring of HTTP/S network requests // for a specific build variant at compile time. setInstrumentationEnabled(false) } } } }
Groovy
android { // ... buildTypes { debug { FirebasePerformance { // Set this flag to 'false' to disable @AddTrace annotation processing and // automatic monitoring of HTTP/S network requests // for a specific build variant at compile time. instrumentationEnabled false } } } }
השבתת הפלאגין באמצעות דגל מאפיין הפרויקט
באמצעות דגל Project Property, אפשר להשבית את הפלאגין Performance Monitoring לכל הווריאנטים של ה-build בזמן הידור.
מוסיפים את הדגל הבא לקובץ gradle.properties
ומגדירים אותו ל-false
כדי להשבית את הפלאגין Performance Monitoring.
// ... // Set this flag to 'false' to disable @AddTrace annotation processing and // automatic monitoring of HTTP/S network requests // for all build variants at compile time. firebasePerformanceInstrumentationEnabled=false
השבתה של ספריית Android של Performance Monitoring
אם משביתים את ספריית Performance Monitoring בזמן הידור, אפשר לבחור אם כדי לאפשר לאפליקציה להפעיל את הספרייה בזמן הריצה.
השבתת הספרייה בזמן הידור (compile), אבל מתן הרשאה לאפליקציה להפעיל אותה בזמן הריצה
צריך להוסיף את רכיב ה<meta-data>
הבא ל-AndroidManifest.xml
של האפליקציה
file:
<application> <meta-data android:name="firebase_performance_collection_enabled" android:value="false" /> </application>
להשבית את הספרייה בזמן הידור (compile), אבל אין לאפשר לאפליקציה להפעיל אותה בזמן הריצה
צריך להוסיף את רכיב ה<meta-data>
הבא ל-AndroidManifest.xml
של האפליקציה
file:
<application> <meta-data android:name="firebase_performance_collection_deactivated" android:value="true" /> </application>
השבתת האפליקציה בזמן הריצה באמצעות Remote Config
באמצעות Firebase Remote Config אפשר לבצע שינויים בהתנהגות ובמראה של האפליקציה שלך, ולכן הוא מספק דרך אידיאלית לאפשר לך להשבית את Performance Monitoring במופעים של האפליקציה שנפרסו.
כדי להשבית את איסוף הנתונים של Performance Monitoring בפעם הבאה שהאפליקציה ל-Android תופעל, משתמשים בקוד לדוגמה שמופיע בהמשך. למידע נוסף על השימוש ב-Remote Config באפליקציה ל-Android, ראו שימוש ב-Firebase Remote Config ב-Android.
מוודאים ש-Remote Config נמצא בקטע
dependencies
בקובץ Gradle של המודול (ברמת האפליקציה) (בדרך כלל<project>/<app-module>/build.gradle.kts
או<project>/<app-module>/build.gradle
):Kotlin+KTX
implementation("com.google.firebase:firebase-config-ktx:22.0.0")
Java
implementation("com.google.firebase:firebase-config:22.0.0")
הגדרת Remote Config והשבתה של Performance Monitoring אם
perf_disable
מוגדר ל-true
:Kotlin+KTX
// Setup remote config val config = Firebase.remoteConfig // You can uncomment the following two statements to permit more fetches when // validating your app, but you should comment out or delete these lines before // distributing your app in production. // val configSettings = remoteConfigSettings { // minimumFetchIntervalInSeconds = 3600 // } // config.setConfigSettingsAsync(configSettings) // Load in-app defaults from an XML file that sets perf_disable to false until you update // values in the Firebase Console // Observe the remote config parameter "perf_disable" and disable Performance Monitoring if true config.setDefaultsAsync(R.xml.remote_config_defaults) .addOnCompleteListener { task -> if (task.isSuccessful) { Firebase.performance.isPerformanceCollectionEnabled = !config.getBoolean("perf_disable") } else { // An error occurred while setting default parameters } }
Java
// Setup remote config final FirebaseRemoteConfig config = FirebaseRemoteConfig.getInstance(); // You can uncomment the following two statements to permit more fetches when // validating your app, but you should comment out or delete these lines before // distributing your app in production. // FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder() // .setMinimumFetchIntervalInSeconds(3600) // .build(); // config.setConfigSettingsAsync(configSettings); // Load in-app defaults from an XML file that sets perf_disable to false until you update // values in the Firebase Console //Observe the remote config parameter "perf_disable" and disable Performance Monitoring if true config.setDefaultsAsync(R.xml.remote_config_defaults) .addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if (task.isSuccessful()) { if (config.getBoolean("perf_disable")) { FirebasePerformance.getInstance().setPerformanceCollectionEnabled(false); } else { FirebasePerformance.getInstance().setPerformanceCollectionEnabled(true); } } else { // An error occurred while setting default parameters } } });
צריך להוסיף את הקוד הבא אל
MainActivity.java
כדי לאחזר ולהפעיל ערכים של Remote Config:Kotlin+KTX
// Remote Config fetches and activates parameter values from the service val config = Firebase.remoteConfig config.fetch(3600) .continueWithTask { task -> if (!task.isSuccessful) { task.exception?.let { throw it } } config.activate() } .addOnCompleteListener(this) { task -> if (task.isSuccessful) { // Parameter values successfully activated // ... } else { // Handle errors } }
Java
//Remote Config fetches and activates parameter values from the service final FirebaseRemoteConfig config = FirebaseRemoteConfig.getInstance(); config.fetch(3600) .continueWithTask(new Continuation<Void, Task<Boolean>>() { @Override public Task<Boolean> then(@NonNull Task<Void> task) throws Exception { if (!task.isSuccessful()) { throw task.getException(); } return config.activate(); } }) .addOnCompleteListener(new OnCompleteListener<Boolean>() { @Override public void onComplete(@NonNull Task<Boolean> task) { if (task.isSuccessful()) { // Parameter values successfully activated // ... } else { // Handle errors } } });
כדי להשבית את Performance Monitoring במסוף Firebase, יוצרים פרמטר perf_disable בפרויקט של האפליקציה ומגדירים את הערך שלו כ-
true
.השינוי הזה יגרום לקריאות 'ללא פעולה' לערכת ה-SDK של Performance Monitoring שיחות (NOOP), ביטול כל השפעות משמעותיות על ביצועי האפליקציה כתוצאה משימוש ערכת ה-SDK Performance Monitoring באפליקציה שלך.
אם מגדירים את הערך של perf_disable כ-
false
, הערך של Performance Monitoring יישאר מופעל.