UPDATE: This page is obsolete. For the latest documentation about using Proguard, see https://developer.android.com/studio/build/shrink-code.html.
ADT 17 brings a number of improvements to the ProGuard integration.
First, we've updated the bundled version from 4.4 to 4.7. Along with a number of other fixes and enhancements (see the ProGuard documentation at http://proguard.sourceforge.net/), this fixes the dreaded "Conversion to Dalvik format failed with error 1" error some users have experienced. We've also updated the code which launches ProGuard, which should hopefully address a number of "spaces in paths" issues.
Second, we've changed the way configuration files are handled.
In previous releases, when you created a new Android project in ADT, we would copy a default "proguard.cfg" file into your project. This file contained a number of rules necessary for using ProGuard with Android, such as disabling certain optimizations not compatible with Android, adding "keep" rules to prevent shrinking methods only referenced from XML, etc.
However, over time, we've both discovered bugs in the default configuration, and of course as the Android API keeps evolving new additions to the rules are necessary as well. The problem we've run into is that users now have stale copies of the old proguard.cfg file in their projects. We've added some lint rules to detect some known bad patterns -- however, when users start editing and reorganizing their own proguard configuration files it gets very difficult to determine if a file is "up to date" with respect to the current recommendations.
Furthermore, most users don't want to read the ProGuard documentation and tweak the configuration -- they just want to get their applications shrunk and obfuscated before uploading it to the Market.
Therefore, as of ADT 17 we've split the configuration file in two halves:
The critical point is that the default set of rules is no longer copied into the project. It resides in the tools install (specifically
The project specific flags are any local additions to the ProGuard configuration, such as specific
Note that this behavior is not mandatory. You can continue to completely specify the complete ProGuard configuration in your project.
To make this all work, we've changed the meaning of the
As of ADT 17, the proguard.config property refers to a path instead, so you can specify as many configuration files as you want. These are all joined together by ProGuard. By default, ProGuard is turned off, but the
(You can use
So, to enable ProGuard in the default way, simply uncomment the above line. You'll pick up all the default Android ProGuard configuration flags from the tools directory, and when we update the tools to fix bugs or update the configuration based on Android changes, you'll automatically be using them.
If you want to completely control your ProGuard configuration, simply specify just your own configuration file instead. Note that ProGuard typically doesn't let you subtract flags, so if you disagree with one of the default flags, you'll need to copy the global configuration into your own files and remove the lines you want to disable. One such flag you might want to consider is the
The default configuration file in ADT 17 has been updated a fair bit, so if you're not going to be using it directly, you might want to compare your own copy with the new copy to see if you're missing anything. We've added some more comments to explain the various flags.
Now, everything explained above refers to new projects created from this point forward. What about existing projects?
Don't worry, we don't touch them. Everything continues to work just as it does today; none of your flags are changed automatically. However, we suspect that most developers are not using a deliberate configuration, they're just using what they got when they created their project, and they might not be aware that their configuration is out of date. To help users become aware of this whole issue, we've added a new lint rule to detect this scenario:
Finally, note that the
Recent Changes >