1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ネストされたクラスに親クラスの@Keepは反映されるのか

Last updated at Posted at 2025-01-31

Question

こんなdataクラスがあったとします。

@Keep
data class HogeResponse(
    val result: Result,
) {

    data class Result(
        val hoge: Boolean,
    )
}

親クラスのHogeResponseの方には@Keepがあるので、難読化されなそう。
しかし、ネストされたResultの方には@Keepが付いていません。

この場合、Resultクラスは難読化されるでしょうか?

結論

難読化されてしまいます。
ネストされたクラスには親クラスの@Keepが反映されません。

実験

Result@Keepがある or なしで生成したapkに差分があるかを確認します。
AndroidStudioのBuildタブ > Analyze APKもしくはツリーの中から直接apkファイルを開くと確認できました。

@Keepあり
@Keepあり.png

@Keepなし
@Keepなし.png

@Keepありの場合は、HogeResponse$Resultのツリーがあることと、HogeResonse内でもResultクラスを確認できるため、難読化されていないことがわかります。

対して@Keepなしの場合は、HogeResponse$Resultのツリーがないことと、HogeResonse内でもResultクラスが確認できません。難読化によって、M0.dに変換されているようでした。

まとめ

親クラスに@Keepつけてる場合は、ネストされたクラスにも@Keepつけようね。

補足:ChatGPTにも聞いてみた

スクリーンショット 2025-01-24 17.43.48.png

とのこと。見解一致です。めでたしめでたし👏

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?