I was asked to crate a simple app for android. The first one in fact that I\'ll be paid for, so I really don\'t want to screw it up :). One of the requirements was that the
The article on the official dev site is out of date. Starting with SDK Tools r17 they changed the way the ProGuard configuration works. Basically they split what used to be proguard.cfg
into two files (and also simply made them .txt files): proguard-android.txt
and proguard-project.txt
. proguard-android.txt
resides in your {SDK dir}\tools\proguard
directory and proguard-project.txt
is in each of your project directories.
They split the file so that general configuration/flags that the Android team deems pretty standard will be in the proguard-android.txt
file and can be updated (basically silently) with each SDK Tools revision. And then any developer/project specific flags, the developer can add to the proguard-project.txt
file.
This is why you noticed everything in your proguard-project.txt
file was commented out, because in general most people don't have any project specific needs, they just want to run ProGuard with standard settings and be done with it.
For reference (a very good explanation): http://tools.android.com/recent/proguardimprovements
Step-by-Step (day by day :P)
(Using Eclipse IDE) To enable ProGuard and it's shrinking and obfuscation using only the default settings:
project.properties
uncomment the line that says: proguard.config=${sdk.dir}\tools\proguard\proguard-android.txt:proguard-project.txt
If you created the project before r17 then you might not see the same things. If that's the case I suggest you create a new dummy project (after updating SDK Tools) and just copy over the proguard-project.txt
and project.properties
files.
That's it! ProGuard will now be enabled and it will run, but only on release builds (when you use Android Tools and export a signed/unsigned apk).
When you make a release build you'll notice that a new ProGuard folder will be created in your project folder. Within this folder you find four files with stuff like what classes/methods were kept or removed. Also note that when you obfuscate, you'll also obfuscate your stacktraces in the event of errors.
Edit: (9/4/12) Just wanted to update this answer to reflect changes in Tools r20.
The Android team has now added one additional proguard configuration file. It is proguard-android-optimize.txt
and it also resides in the {SDK dir}\tools\proguard
directory. This file is the same as the original proguard-android.txt
config file, except it has proguard optimization turned on.
This additional file was added for convenience for those who wanted to turn on optimizations (maybe so they can do stuff like strip out Log calls, which requires optimizations be turned on). Now you can simply point to this file instead in your project.properties
file like so:
proguard.config=${sdk.dir}\tools\proguard\proguard-android-optimize.txt:proguard-project.txt
As before, don't try to alter any of the proguard-android...
config files. Any project specific flags should go in the proguard-project.txt
file in your project folder.