Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Always running proguard before Android dex'ing in Eclipse

Is there a way to make Eclipse always run proguard before dex'ing when trying to run an Android Application? e.g. some way of seamlessly inserting it as a build step?

By default it will run when exporting, but I need it to always run, even when e.g. just doing a normal "Run" or "Debug" from the menu / keyboard.


For context, the reason this is relevant is that I'm running into the "too many opcodes / no expanded opcodes" (http://code.google.com/p/android/issues/detail?id=26203) issues with my build in Eclipse. It's not an issue for ant builds because they run proguard, which strips all of the unused code. Up until now I've been manually stripping unused things from my third party dependencies, but it is getting somewhat ridiculous.

Also, as a side benefit, it should dramatically speed up my build, because a shrink-only proguard run is way, way faster than dex'ing and it removes most of the code that needs to be dex'ed.

like image 351
Darin Tay Avatar asked Jul 04 '12 00:07

Darin Tay


1 Answers

This behavior is hard-coded in the builder of the Eclipse plugin in the Android Development Tools. You could adapt its source code (Android Tools) so the builder behaves more like the export wizard (or internally, the BuildHelper class behaves more like the ExportHelper class). That might not be much fun to maintain though.

Alternatively, you can run Ant from Eclipse.

Also alternatively, the commercial, closed-source sibling of ProGuard, DexGuard, integrates the functionality of ProGuard and of dx (and apkbuilder, jarsign, zipalign). It can be configured to shrink/obfuscate/optimize for debug/release builds in Eclipse and in Ant.

(I am the developer of ProGuard and DexGuard)

like image 145
Eric Lafortune Avatar answered Oct 20 '22 23:10

Eric Lafortune