R8 resource shrinking path never runs aapt2 optimize (resource path shortening / sparse encoding have no effect with R8)

Đang mở
#534 0 bình luận 2 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 6 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
52/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
android, java
Lĩnh vực
build-system, mobile-dev

Hướng nghiên cứu

Đọc rules/android_binary/r8.bzl, sau đó so sánh process_resource_shrinking_r8 với _process_optimize trong rules/android_binary/impl.bzl. Xem xét patch được tham chiếu và thêm các bài kiểm thử bao phủ đường dẫn R8 khi tính năng rút ngắn đường dẫn tài nguyên hoặc mã hóa sparse được bật. Hoàn thành khi các tùy chọn đó có hiệu lực trên APK tài nguyên R8 mà không thay đổi hành vi khi chúng bị tắt.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

The legacy ProGuard pipeline runs aapt2 optimize after resource shrinking (see _process_optimize in rules/android_binary/impl.bzl). The R8 resource shrinking path (process_resource_shrinking_r8 in rules/android_binary/r8.bzl) stops after producing the shrunk resource APK and never invokes optimize.

As a result, //rules/flags:experimental_android_resource_path_shortening and the enable_sparse_encoding attribute silently do nothing when R8 is used.
There's no error or warning — they're just ignored, which is easy to miss when migrating and comparing APK sizes against a Gradle build (AGP applies these optimizations as part of its R8 pipeline). We confirmed on our app that with the flag set, resource paths in the APK stay unshortened on the R8 path.

We're running a patch that wires _resources.optimize into the R8 path after the shrinking step, after which path shortening works as expected: https://github.com/Dolfik1/rules_android/commit/fa29d470bbe9f609c83a0993259a29a8e6994371

Notes:

  • _resources.optimize already gates itself on the path-shortening flag, compilation mode and ACLs, so the added call is a no-op unless those are enabled — behavior for anyone not using these features is unchanged.
  • Resource name obfuscation is left disabled: it needs the resource optimization config that the R8 resource shrinker doesn't produce (resource_optimization_config = None). Could be a follow-up.

Happy to send a PR with tests if this looks right.

Ngôn ngữ chính
Java
Star
205
Fork
113
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của bazelbuild/rules_android

Tất cả issue của bazelbuild/rules_android

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.