androidproguardandroid-r8

How to profile/optimize obfuscation with R8


Recently my team worked on updating our AGP as we've been severely behind and with fullMode being set as default option for R8 we've experienced some issues regarding build times. Locally building a clean release version of our app takes around 15 minutes, but on our CI machine the obfuscation process takes significantly longer (up to an hour). The machine that runs the code isn't worse than our work machines and we've been unable to pinpoint where exactly the problem lies as R8 ignores -verbose option from Proguard.

What troubleshooting steps could I execute in order to gain some more information on what is the root cause of this?


Solution

  • It is possible to get R8 to measure the time spent in each stages of the compilation pipeline by setting the system property -Dcom.android.tools.r8.printtimes, e.g.

    ./gradlew assembleRelease --no-daemon -Dcom.android.tools.r8.printtimes
    

    This will print the timing report to standard out. Based on that you can file an issue on R8, and we can take a look if something stands out.

    We recently did some optimizations based on findings on the Monzo app, see https://issuetracker.google.com/378464445. You could try to update to R8 8.9.21, and see if it helps for your app. See Replacing R8 in Android Gradle plugin on how to do that.