[Xamarin.Android.Build.Tasks] redistribute proguard-android.txt from Android gradle plugin by jonathanpeppers · Pull Request #9485 · dotnet/android (original) (raw)

Context: https://discord.com/channels/732297728826277939/732297837953679412/1303383272918618163

A customer found their app grew in size when building on Windows
versus macOS.

The difference being a file that was passed to the <R8/> task on
Windows, but not on macOS:

C:\Users\[username]\AppData\Local\Android\Sdk\tools\proguard\proguard-android.txt

tools is ancient, as any Android SDK should be using
cmdline-tools now.

Let's stop using this file as a default set of proguard rules.

But we need to use the right set of proguard rules, reading
the text of the old one:

This file is no longer maintained and is not used by new (2.2+)
versions of the # Android plugin for Gradle. Instead, the Android
plugin for Gradle generates the # default rules at build time and
stores them in the build directory.

I found the source code for the gradle task that generates the new
files at:

In order to get this file, we can setup an empty gradle project
using the Android gradle plugin:

plugins {
    id 'com.android.application' version '8.7.0'
}

Which, hopefully, dependabot is able to update this version.

Then we can run the task:

.\gradlew extractProguardFiles

This outputs files such as:

src\proguard-android\build\intermediates\default_proguard_files\global\proguard-android-optimize.txt-8.7.0
src\proguard-android\build\intermediates\default_proguard_files\global\proguard-android.txt-8.7.0
src\proguard-android\build\intermediates\default_proguard_files\global\proguard-defaults.txt-8.7.0

For now, I simply redistributed the proguard-android.txt file, but
we could consider making proguard-android-optimize.txt useable in
the future. I believe the only difference is the
-allowaccessmodification flag, which users could put in their own
proguard rules.