Status Update
Comments
ch...@google.com <ch...@google.com> #2
Thanks for the detailed bug report and for taking the time to identify the change causing this.
From a first look this seems to be working as intended. In R8 3.0, the behavior of R8 in presence of -dontoptimize
was changed to be more aggressive (
Could you try building with R8 3.0.46, which should not have the more aggressive behavior, to validate that it is indeed the above two CLs that significantly reduce the dex size?
In order to fix this, you would need to remove -dontoptimize
from your Proguard configuration. To start with, you could maybe replace -dontoptimize
by the following rule, which should effectively mark the matched items as not subject to optimization, due to the absence of ,allowoptimization
.
-keep,allowaccessmodification,allowobfuscation,allowshrinking class * { <fields>; <methods>; }
You could then try to narrow down the set of items matched by this rule to reduce the dex size of your app.
mi...@gmail.com <mi...@gmail.com> #3
Hi team, Thank you a lot for your reply. Let me try your suggestion and come back on this
mi...@gmail.com <mi...@gmail.com> #4
mi...@gmail.com <mi...@gmail.com> #5
Hi Team, Sorry for the delay. There is some update from my side:
We do not have the size issue with Android Gradle Plugin 4.2.2 which use the R8 version 2.2.71.
We do see a 1.6MB (2%) reduction in the binary size when enforcing to use of the R8 version 3.0.64 with AGP 7.1.2 (Update from R8 2.2.71 and AGP 4.2.2) As you asked, I tried multiple versions of R8, and here is the result:
R8 version | Note on rule | Dex size |
---|---|---|
3.0.46 | 32.4MB | |
3.0.47 | 31.8MB | |
3.0.64 (Enforce to use in the project now with AGP 7.1.2) | 27.3MB | |
3.1.66 (default R8 version from AGP 7.1.2) | 36.8MB | |
3.1.66 | Use proguard-android-optimize.txt | 27.3MB |
3.1.66 | Use proguard-android-optimize.txt Apply "-keep,allowaccessmodification,allowobfuscation,allowshrinking class * { <fields>; <methods>; }" | 36.3MB |
Conclusion:
Look like the dex size spike is not only caused by the two commits you mentioned.
Applying "proguard-android-optimize.txt" seems to fix the issue. As Google recommends using "proguard-android-optimize.txt"(
ch...@google.com <ch...@google.com> #6
Marking this as working as intended as the regression was caused by -dontoptimize
. Moving to proguard-android-optimize.txt
should avoid this problem as these rules do not include -dontoptimize
.
Description
Dear R8 team,
After the update to AGP 7.1.2, our App Size increased by 5% (caused by the dex files size increase of 17.3%).
Checked out your code, compile and try on the project. I figured out the dex file size spike caused by this commithttps://r8-review.googlesource.com/c/r8/+/61680
In an early investigation of the dex files:
There are a lot more lambda classes is keeping in the dex files after applying the commit to R8. For example:
Or
Or
It's challenging to create a demo project with the same issue. From the commit I provided, would you please help to advise:
ps: Currently, we force the project to use R8 3.0.x to avoid the case, but for some reason, we soon have to use the new R8 version.