אם נתקלתם בבעיות, ב-R8 יש כלים שיעזרו לכם לפתור אותן. אם אתם לא מצליחים לפתור בעיה ב-R8, אתם יכולים לדווח על באג.
טיפים כלליים
בדרך כלל, בעיות ב-R8 הן ייחודיות לאפליקציה שלכם, אבל ריכזנו כאן כמה טיפים כלליים שיעזרו לכם לנפות באגים בקלות רבה יותר:
השבתה זמנית של האפליקציה: R8 מבצע ערפול קוד כחלק מתהליך האופטימיזציה שלו. בדרך כלל, ערפול לא גורם לשגיאות, אבל הוא מקשה על ניפוי באגים. מוסיפים את הדגלים ‑dontobfuscate ו-‑dontoptimize לקובץ הכללים לשמירה כדי לאתר קוד בעייתי.
בדיקת השתקפות: אם נתקלתם בחריגה מסוג no such element, למשל:
Caused by: java.util.NoSuchElementException: Collection contains no element
matching the predicate in the stack trace ,
בדרך כלל, המשמעות של היוצא מן הכלל היא שהשדה הרלוונטי נמצא בשימוש באמצעות השתקפות, וצריך להוסיף כלל שמאפשר לשמור אותו.
בדיקת קוד בייט: רוב הבעיות ב-R8 מחייבות בדיקת קוד בייט, שאפשר לבצע באמצעות כלים כמו APK Analyzer.
איך בודקים אילו כללים חלים
כדי להפיק דוח מלא של כל הכללים שחלות על R8 בזמן ה-build של הפרויקט, צריך לכלול את הקטע הבא בקובץ proguard‑rules.pro של המודול של האפליקציה:
אפשר לציין כל נתיב ושם קובץ. אם לא מציינים נתיב או שם קובץ, דוח הכללים יופיע ב-R8 ב-<module-name>/build/outputs/mapping/<build-type>/configuration.txt.
הסיבה לכך שהקוד נשמר
אם אתם רואים קוד שנשאר ולא ציפית שהוא יוסר, תוכלו להשתמש באפשרות ההגדרה ‑whyareyoukeeping כדי להבין למה הקוד נשאר. R8 יוצר נתיב מהקוד שנשמר לאחת מנקודות הכניסה של האפליקציה. למידע נוסף, עיינו במסמכי העזרה של ‑whyareyoukeeping במדריך של Proguard.
שחזור של נתיב הקריאה החוזרת המקורי
הקוד שמעובד על ידי R8 משתנה בדרכים שונות, כך שניתוח עקבות הקריאה לא מתייחס יותר לקוד המקורי. לדוגמה, מספרי השורות והשמות של הכיתות והשיטות יכולים להשתנות. כדי לשחזר את מעקב הסטאק המקורי, ב-R8 יש את כלי שורת הפקודה retrace, שמצורף לחבילת הכלים של שורת הפקודה.
כדי להשתמש ב-retrace, צריך לספק לו קובץ מיפוי וקובץ מעקב סטאק. קובץ המיפוי, שנקרא mapping.txt, נכלל בחבילת Android App Bundle (AAB) באופן אוטומטי. פרטים נוספים זמינים במסמכי העזרה בנושא retrace ובמאמר במרכז העזרה של Play Console בנושא ביטול ההסתרה של נתוני מעקב בסטאק של קריסה.
דוגמאות התוכן והקוד שבדף הזה כפופות לרישיונות המפורטים בקטע רישיון לתוכן. Java ו-OpenJDK הם סימנים מסחריים או סימנים מסחריים רשומים של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-07-27 (שעון UTC).
[[["התוכן קל להבנה","easyToUnderstand","thumb-up"],["התוכן עזר לי לפתור בעיה","solvedMyProblem","thumb-up"],["סיבה אחרת","otherUp","thumb-up"]],[["חסרים לי מידע או פרטים","missingTheInformationINeed","thumb-down"],["התוכן מורכב מדי או עם יותר מדי שלבים","tooComplicatedTooManySteps","thumb-down"],["התוכן לא עדכני","outOfDate","thumb-down"],["בעיה בתרגום","translationIssue","thumb-down"],["בעיה בדוגמאות/בקוד","samplesCodeIssue","thumb-down"],["סיבה אחרת","otherDown","thumb-down"]],["עדכון אחרון: 2025-07-27 (שעון UTC)."],[],[],null,["# Test and troubleshoot the optimization\n\nAfter you enable app optimization, check that your app is working as intended\nand that the R8 configuration is doing what you expect. The general steps are as\nfollows:\n\n1. **Test your app's critical user journeys (CUJs):** For example, make sure that users can sign in and do other important tasks.\n2. **Measure performance gains using benchmarks:** [Benchmark your app](/topic/performance/benchmarking/benchmarking-overview) before and after enabling app optimization.\n\nIf you find issues, R8 provides tools to help you troubleshoot. If you're unable\nto solve an issue with R8, [file a bug](https://b.corp.google.com/issues/new?component=326788&template=1025938&pli=1).\n\nGeneral tips\n------------\n\nIssues with R8 are often unique to your app, but here are some general tips to\nmake debugging easier:\n\n- **Temporarily turn off obfuscation:** R8 obfuscates code as part of its optimization process. Obfuscation usually isn't the cause of errors, but obfuscation makes errors more difficult to debug. Add the `‑dontobfuscate` and `‑dontoptimize` flags to the keep rules file to help you pinpoint problematic code.\n- **Check for reflection:** If you run into a *no such element* exception such\n as\n\n `Caused by: java.util.NoSuchElementException: Collection contains no element\n matching the predicate in the stack trace` ,\n\n the exception usually means the field in question is being used through\n reflection and you have to add a keep rule.\n- **Inspect bytecode:** Most R8 issues require bytecode inspection, which you\n can do with tools such as the [APK Analyzer](/studio/debug/apk-analyzer).\n\nCheck which rules are applied\n-----------------------------\n\nTo output a full report of all the rules that R8 applies when building your\nproject, include the following in your app's module\n`proguard‑rules.pro` file: \n\n -printconfiguration \u003coutput-dir\u003e/\u003creport-name\u003e.txt\n\nYou can specify any path and filename. If you don't specify a path or filename,\nR8 outputs the rules report at `\u003cmodule-name\u003e/build/outputs/mapping/\u003cbuild-type\u003e/configuration.txt`.\n\nUnderstand why code was kept\n----------------------------\n\nIf you see kept code that you expected to be removed, use the configuration\noption `‑whyareyoukeeping` to help understand why the code was\nkept. R8 outputs a path from the kept code to one of your app's [entry\npoints](/topic/performance/app-optimization/add-keep-rules#how-write). For more information, see the\n[`‑whyareyoukeeping`](https://www.guardsquare.com/manual/configuration/usage)\ndocumentation in the Proguard manual.\n\nRecover the original stack trace\n--------------------------------\n\nCode processed by R8 is changed in various ways so that the stack trace no\nlonger refers to the original code. For example, line numbers and the names of\nclasses and methods can change. To recover the original stack trace, R8 provides\nthe retrace command-line tool, which is bundled with the command-line tools\npackage.\n\nTo use retrace, give it a *mapping file* and a stack trace file. The mapping\nfile, called `mapping.txt`, is automatically bundled with your Android App\nBundle (AAB). For more details, see the [retrace](/studio/command-line/retrace) documentation and the Play\nConsole Help Center article about how to [de‑obfuscate crash stack\ntraces](https://support.google.com/googleplay/android-developer/answer/9848633).\n| **Warning:** If you're shipping APKs, the `mapping.txt` file isn't automatically bundled with your APK. Android Studio saves the mapping file in the `/build/outputs/mapping/` directory. The mapping file is overwritten every time you build your project, so you must save a copy each time you publish a new release."]]