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

オープン
#534 コメント 0 件 リアクション 2 件 担当者 0 名 GitHub で見る

メンテナーはふだん 6 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
52/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
静か
技術スタック
android, java

調査の方向性

rules/android_binary/r8.bzlを読み、次にrules/android_binary/impl.bzlのprocess_resource_shrinking_r8と_process_optimizeを比較します。参照されているパッチを確認し、リソースパスの短縮またはスパースエンコーディングを有効にしたR8パスを対象とするテストを追加します。これらのオプションが無効な場合の動作を変更せずに、R8リソースAPKでそれらのオプションが有効になることを確認できれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Java
スター
205
フォーク
113
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

bazelbuild/rules_android のほかの issue

bazelbuild/rules_android の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。