Chuyển đến nội dung
Skillpedia
Ứng dụng di động10k · #11927

r8-analyzer

Skill này làm gì

Skill này kiểm tra các file build Android và quy tắc giữ lại R8 để tìm các quy tắc trùng lặp hoặc quá rộng. Nó giúp giảm kích thước ứng dụng và sửa các thiết lập ProGuard khó hiểu. Nó dành cho lập trình viên Android quản lý việc thu gọn và tối ưu ứng dụng.

Khi nào nên dùng

  • ✓Khi bạn muốn làm ứng dụng Android nhỏ hơn bằng cách dọn các quy tắc giữ lại R8.
  • ✓Khi cấu hình ProGuard hoặc R8 của bạn khó hiểu và bạn muốn nó được rà soát.
  • ✓Khi bạn muốn kiểm tra xem một Android Gradle Plugin cũ có nên chuyển sang thiết lập mới hơn để tối ưu ứng dụng không.

Liên kết skill

https://github.com/android/skills/blob/main/performance/r8-analyzer/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/android/skills/blob/main/performance/r8-analyzer/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Rà soát các quy tắc giữ lại R8 của tôi và cho tôi biết quy tắc nào trùng lặp hoặc quá rộng.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Skill kiểm tra các file build xem phiên bản Android Gradle Plugin và cài đặt R8. Sau đó nó đi theo một trong hai hướng phân tích, tùy phiên bản plugin, để tìm các quy tắc trùng lặp và quá rộng.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

Step 1. Setup and configuration check

  • Inspect build.gradle, build.gradle.kts, and gradle.properties.
  • Use references/CONFIGURATION.md to identify missing optimizations.
  • AGP : If the version is lower than 9.3, suggest migration to 9.3 for the simplified optimization {} DSL and the Configuration Analyzer task.
  • Full mode : Verify android.enableR8.fullMode=false is removed from the gradle.properties file.

Step 2. Analysis path selection

  • Inspect build.gradle, build.gradle.kts, settings.gradle, settings.gradle.kts, gradle.properties, and libs.versions.toml to get the AGP and R8 versions. An R8 version pinned in settings.gradle(.kts) replaces the R8 bundled with AGP.

  • Find the app module (usually app) and a build variant with R8 enabled (usually release). The following commands use them as <module> and <Variant>, for example :app:minifyReleaseWithR8.

  • The helper scripts are in this skill's scripts/ directory. In the following commands, <skill_dir> is this skill's directory. Run every command from the project root.

  • If AGP >= 9.3.0 : Proceed to Path A (Standalone Task).

  • If AGP < 9.3.0 : Proceed to Path B (Quantitative).

Path A: Standalone Gradle task (AGP >= 9.3.0)

  • Step 1: Check requirements : Python and the protobuf package 6.33.4 or later are mandatory (used by scripts/keep_radius_pb2.py). Install it with pip install "protobuf>=6.33.4"; versions lower than 6.33.4 fail on import with a VersionError or ImportError.
  • Step 2: Run standalone task on R8-enabled build : For the module and variant you found during path selection, run ./gradlew :<module>:analyze<Variant>R8Config (for example, ./gradlew :app:analyzeReleaseR8Config). It generates the report in <module>/build/reports/r8/ (for example, app/build/reports/r8/r8-config-analyzer-release.pb). You must wait for this command to finish before proceeding.
  • Step 3: Convert to JSON : You must explicitly run the conversion script scripts/convert_pb_to_json.py as python3 <skill_dir>/scripts/convert_pb_to_json.py with arguments <module>/build/reports/r8 and tmp/keepradius/keepruleradius.json. Wait for this command to finish.
  • Step 4: Analyze : You must explicitly run the analysis script scripts/analyze.py by executing python3 <skill_dir>/scripts/analyze.py tmp/keepradius/keepruleradius.json. This outputs tmp/keepradius/analysis_result.txt. Wait for this command to finish.

Path B: Invoke R8 release build (AGP < 9.3.0)

  • Step 1: Check requirements : Python and the protobuf package 6.33.4 or later are mandatory: pip install "protobuf>=6.33.4".
  • Step 2: Generate and analyze : You must run the shell commands described in references/FULL_BUILD_CONFIG_ANALYZER.md to temporarily update the R8 version in settings.gradle(.kts) to 9.4.34 or later (so R8 generates the report), generate the proto report in tmp/r8analysis/, convert it to tmp/r8analysis/keepruleradius.json, analyze the result, and revert the temporary settings.gradle(.kts) change.
  • Step 3: Analyze : Verify that the analysis outputs tmp/r8analysis/analysis_result.txt for scores and rule impact metrics.

Step 3. Report generation

  • Format : Follow references/REPORT_FORMAT.md strictly.
  • Redundant rules : Check keep rules against references/INSPECT-RULES.md. If a keep rule matches a pattern in references/INSPECT-RULES.md, include the guidance and remediation from that reference alongside the impact metrics.
  • Input : Extract metrics (Scores, Impacts, Example Classes, rule origins) directly from the generated file tmp/keepradius/analysis_result.txt if using Path A, or tmp/r8analysis/analysis_result.txt if using Path B.
  • Output : Short progress updates are fine while Gradle runs; the final message is the report only. Output only the raw Markdown report in the chat. Do not output conversational filler (for example, "Here is your report..."). Do not provide recommendations, next steps, or any other text outside of the sections defined in references/REPORT_FORMAT.md.
Câu hỏi thường gặp

Nó có sửa các lỗi build Gradle nói chung không?

Không. Những lỗi đó nằm ngoài skill này, vì skill tập trung vào kích thước ứng dụng và các quy tắc giữ lại.

Nó mong đợi phiên bản plugin nào?

Với các phiên bản 9.3.0 trở lên, nó dùng một tác vụ độc lập. Với các phiên bản cũ hơn, nó dùng một đường phân tích có đo đạc.

Nó có kiểm tra cờ full mode không?

Có. Nó kiểm tra cờ full mode cũ đã được gỡ khỏi gradle.properties chưa.

Chi tiết

Mô tả gốc của tác giả

Analyzes Android build files and R8 keep rules to identify redundancies, broad package-wide rules, and rules that subsume library consumer keep rules. Use this skill when developers want to optimize their Android app's size, remove redundant or overly broad keep rules, or troubleshoot ProGuard configurations. Don't use for general Gradle build errors, Compose UI performance, or runtime CPU profiling.

repo: android/skills

Độ phổ biến

Sao GitHub
10k
Vị trí xếp hạng
#11927
Giấy phép
Apache-2.0
Cập nhật
29/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự