با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
پس از فعال کردن بهینهسازی برنامه، بررسی کنید که آیا برنامهتان طبق برنامه کار میکند و پیکربندی R8 همان کاری را که انتظار دارید انجام میدهد. مراحل کلی به شرح زیر است:
سفرهای کاربر مهم (CUJ) برنامه خود را آزمایش کنید: به عنوان مثال، مطمئن شوید که کاربران می توانند وارد سیستم شوند و کارهای مهم دیگر را انجام دهند.
اگر مشکلی پیدا کردید، R8 ابزارهایی را برای کمک به عیب یابی ارائه می دهد. اگر نمیتوانید مشکل R8 را حل کنید، یک اشکال را ثبت کنید .
نکات کلی
مشکلات مربوط به R8 اغلب برای برنامه شما منحصر به فرد است، اما در اینجا چند نکته کلی برای آسان کردن اشکال زدایی وجود دارد:
خاموش کردن موقت مبهم سازی: R8 کد را به عنوان بخشی از فرآیند بهینه سازی خود مبهم می کند. مبهم سازی معمولاً دلیل خطاها نیست، اما مبهم سازی خطاها را دشوارتر می کند. پرچمهای ‑dontobfuscate و ‑dontoptimize را به فایل قوانین نگهداری اضافه کنید تا به شما کمک کند کدهای مشکل دار را به دقت شناسایی کنید.
بررسی انعکاس: اگر به استثنای عنصری مانند
Caused by: java.util.NoSuchElementException: Collection contains no element matching the predicate in the stack trace .
استثنا معمولاً به این معنی است که فیلد مورد نظر از طریق بازتاب استفاده می شود و شما باید یک قانون نگه داشتن اضافه کنید.
بررسی بایت کد: اکثر مشکلات R8 به بازرسی بایت کد نیاز دارند که می توانید با ابزارهایی مانند APK Analyzer انجام دهید.
بررسی کنید که کدام قوانین اعمال می شود
برای خروجی یک گزارش کامل از تمام قوانینی که R8 هنگام ساخت پروژه خود اعمال می کند، موارد زیر را در فایل proguard‑rules.pro ماژول برنامه خود قرار دهید:
شما می توانید هر مسیر و نام فایل را مشخص کنید. اگر مسیر یا نام فایلی را مشخص نکنید، R8 گزارش قوانین را در <module-name>/build/outputs/mapping/<build-type>/configuration.txt خروجی میدهد.
بدانید چرا کد نگه داشته شده است
اگر کد نگهداری میبینید که انتظار داشتید حذف شود، از گزینه پیکربندی ‑whyareyoukeeping برای کمک به درک دلیل نگهداری کد استفاده کنید. R8 یک مسیر از کد حفظ شده به یکی از نقاط ورودی برنامه شما را خروجی می دهد. برای اطلاعات بیشتر، به مستندات ‑whyareyoukeeping در دفترچه راهنمای Proguard مراجعه کنید.
رد پشته اصلی را بازیابی کنید
کد پردازش شده توسط R8 به روش های مختلفی تغییر می کند به طوری که رد پشته دیگر به کد اصلی اشاره نمی کند. به عنوان مثال، شماره خطوط و نام کلاس ها و متدها می توانند تغییر کنند. برای بازیابی پشته اصلی، R8 ابزار خط فرمان retrace را ارائه میکند که با بسته ابزار خط فرمان همراه است.
برای استفاده از retrace، یک فایل نگاشت و یک فایل ردیابی پشته به آن بدهید. فایل نگاشت، به نام mapping.txt ، به طور خودکار با بسته نرم افزاری Android شما (AAB) همراه می شود. برای جزئیات بیشتر، به مستندات ردیابی مجدد و مقاله مرکز راهنمایی کنسول Play در مورد نحوه مبهمسازی ردیابی پشته خرابی مراجعه کنید.
محتوا و نمونه کدها در این صفحه مشمول پروانههای توصیفشده در پروانه محتوا هستند. جاوا و OpenJDK علامتهای تجاری یا علامتهای تجاری ثبتشده Oracle و/یا وابستههای آن هستند.
تاریخ آخرین بهروزرسانی 2025-07-29 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","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-29 بهوقت ساعت هماهنگ جهانی."],[],[],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."]]