Using Google Collections with ProGuard

Just a short post to anyone who uses Google Collections in their applications and ProGuard to obfuscate their code: it won't work because of the way Google Collections has been architected since around the 1.0-rc release.

To get around this, simply include the following in your ProGuard config script:

-dontskipnonpubliclibraryclasses

To quote the Proguard manual , this instruction:

Specifies not to ignore non-public library classes. By default, non-public library classes are skipped while parsing library jars. The classes are typically not relevant during processing, since they don't affect the actual program code in the input jars. Ignoring them reduces memory usage and processing time. Occasionally, a badly designed library may contain a non-public library class that is extended/implemented by a public library class. If the latter library class in turn is extended/implemented by a program class, ProGuard will complain that it can't find the non-public library class, which it had ignored during parsing. This option will overcome that problem, at the cost of greater memory usage and longer processing time.

Once this is done, the build should proceed as normal. In some circumstances (such as mine), your build may run out of memory. In this case, up the memory to the build script by adding the following VM arguments:

-Xms512m -Xmx1024m

Of course, you can vary that based on the memory requirements your build needs.

Hope that helps!

Thoughts on “Using Google Collections with ProGuard”