0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Android Skillsのr8-analyzerのskillについての注意点

0
Last updated at Posted at 2026-06-22

R8っていうのは呼ばれていない関数の削除などの最適化ができるツールなんですが、これで最適化の点数をつけてくれて、評価、最適化のためのフィードバックをくれるAgent Skillがあります。

このスキルを少しだけ見て、気づいたことがあったので書いておきます。

Analysis pathが2つある

Step 2. Analysis path selection
Inspect build.gradle, build.gradle.kts, and gradle.properties and libs.versions.toml to get the R8 version
If R8 >= 9.3.7-dev : Proceed to Path A (Quantitative).
If R8 < 9.3.7-dev : Proceed to Path B (Heuristic).

で、このQiitaで言いたかったのは、
Path Bの場合はヒューリスティック (必ずしも正解を得られるとは限らないものの、経験や直感に基づいて、ある程度満足できるレベルの答えを素早く導き出す「発見的」な手法や思考プロセス) に行われ、Aの場合はツールを使って定量的(Quantitative)に行われる。っていうことだけです。

Path A 定量的(Quantitative)

R8 Configuration Analyzerというのを使います。以下のGradleのオプションを使って、dumpを作ります。

./gradlew assembleRelease \
-Dcom.android.tools.r8.dumpkeepradiustodirectory=$PWD/tmp/r8analysis

これはprotobufのバイナリを作るらしくて、jsonに変換して利用して、pythonで統計処理して、出す。

Path B ヒューリスティック

こっちはルールを見に行って、なぜか消すためのルールなどを探しに行くようです。
主にライブラリとアプリ側でのルールの重複を見つけて、アプリ側でのルールを消すなどを行うのが多いです。

レポート作成

Path A / Path Bに基づいて、

  • Optimization score(最適化スコア): インライン化やメソッド統合などができるコードの割合。
  • Shrinking score(削除スコア): 未使用のクラスやメソッドを削除できるコードの割合。
  • Obfuscation score(難読化スコア): クラス名を難読化できるコードの割合。
Optimization score: [X]% code is available for R8 optimizations (e.g., inlining, merging). [100-X]% of codebase can't be optimized by R8.
Shrinking score: [X]% of code will be optimized by R8 by removing unused classes, fields and methods. [100-X]% of codebase contains redundant classes, fields and methods that can't be removed by R8.
Obfuscation score: [X]% of the codebase is available for R8 to obfuscate.

を出してくれるそうです。

で、ここからが問題なんですが、Path B ヒューリスティック の場合は、ルールの書き方から推測する形のため、そこのクラスの割合などが考慮されないため、 かなりブレを許す形 になってしまうということです。usage.txtやクラスの数などをカウントすることはLLM的には可能ですが、Skillとしては現状(2026/06/22時点)では書いていないです。

で、Path A 定量的(Quantitative) を使うには?

まあAIに言えば多分ググってやってくれるとは思うんですが

Note: To use the R8 Configuration Analyzer, you need R8 version 9.3.7-dev or later. This version comes pre-bundled with Android Gradle Plugin (AGP) 9.3.0-alpha05 and later. To update your R8 version without updating AGP follow the steps in Replacing R8 in AGP.

とのことなので、そのとおりにやりましょう。手軽にやるなら、R8のバージョンを上げれば使えるようですね。

Replacing R8 in Android Gradle plugin
Android Gradle plugin (AGP) ships with R8 embedded (as part of the builder.jar from com.android.tools.build:builder:<agp version> on https://maven.google.com).

To override the embedded version with a prebuilt R8 with version <version>, merge the following into the top level settings.gradle or settings.gradle.kts:

pluginManagement {
    buildscript {
        repositories {
            mavenCentral()
            maven {
                url = uri("https://storage.googleapis.com/r8-releases/raw")
            }
        }
        dependencies {
            classpath("com.android.tools:r8:<version>")
        }
    }
}

R8のバージョンリストはこれかな?
https://r8.googlesource.com/r8/+refs
9.4.3-dev とかが今はあるみたい。(9.4を開くと書いてある)

これをすると、r8-analyzerのskillが確実になります。

R8 Configuration Analyzer での問題がありそうなKeep RuleのランキングをHTMLでみる

バージョンによって、以下でtmp/r8analysisか

./gradlew assembleRelease \
    -Dcom.android.tools.r8.dumpkeepradiushtmltodirectory=tmp/r8analysis

build/outputs/mapping/release/configanalyzer.html に保存されます。

dump keepradius todirectoryを先ほどを使っていましたが、 keepradiushtml を使っています。これではprotobufのバイナリではなく、htmlで出力できるようです。

にあるように問題のあるkeep rule ランキングのようなものが見られます。

image.png

まとめ

R8のバージョンに注意しよう。
Path Aになるようにしよう。
R8 Configuration AnalyzerでHTMLで確認してみよう。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?