The other answers are still mostly right, but since they were written some things have changed.
If you open <android-sdk-root>/sdk/tools/proguard/proguard-android.txt
then you'll see this comment:
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.
What does this mean exactly?
It means that the sdk/tools/proguard/proguard-android.txt
file is irrelevant - the rules written inside it are not actually used. However, it does NOT mean that the line proguardFiles getDefaultProguardFile('proguard-android.txt')
is now useless.
If you use proguardFiles getDefaultProguardFile('proguard-android.txt')
with AGP version 2.2 or higher (which I think is everyone at this point), then the proguard-android.txt
file used will be the one that ships inside AGP itself. Google mention this in the release notes for AGP 2.2:
getDefaultProguardFile now returns the default ProGuard files that Android plugin for Gradle provides and no longer uses the ones in the Android SDK.
How can I see the rules?
If you want to see what rules are applied in the new proguard-android.txt
file from within AGP, then you can check the proguard-android.txt
file that AGP generates when it builds your project. Be aware that this file is only generated when minify runs: therefore this file won't exist in your project until you build your project in a build variant with minifyEnabled
set to true
. AGP will generate the file in your project in the <project-root>/build/intermediates/default_proguard_files/global/
directory.
What if I can't find the file?
Then you can take the hard route and see how the proguard-android.txt
file is generated by looking at the AGP source code. The following instructions are what worked for me for version 3.0.0:
1 - Find the gradle source files
For this I followed this brilliant answer: https://stackoverflow.com/a/44122888/6007104
To summarise:
- Open the directory
gradle/caches/modules-2/files-2.1/com.android.tools.build/gradle-core/
on your machine
- In here are listed the downloaded AGP versions - open the directory you're interested in
- Dig around within this directory for a file named
gradle-core-X-sources.jar
, where X is the version you want. For me that was gradle-core-3.0.0-sources.jar
.
- Copy that jar file somewhere safe, and then unzip it to see the AGP source files hidden inside.
2 - Find the rules
Now you have the source files, you might think it's as simple as finding the file named proguard-android.txt
. Unfortunately, that file doesn't exist - it's dynamically built. Instead, you'll want to find the code within the AGP source where the proguard-android.txt
file is built. For me that was in com/android/build/gradle/ProguardFiles.java
. It turns out that (at time of writing), the rules of proguard-android.txt
are just the rules defined in the com/android/build/gradle/proguard-common.txt
file.