16

After adding Google Guava r09 to our Android project the build time increased significantly, especially the DEX generation phase. I understand that DEX generation takes all our classes + all jars we depend on and translates them to DEX format. Guava is a pretty big jar around 1.1MB

  1. Can it be the cause for the build slowdown?
  2. Are there anything can be done to speed this up?

P.S. Usually I build from Intellij, but I also tried building with Maven - same results.

Thanks

Alex

AlexV
  • 3,836
  • 7
  • 31
  • 37
  • I've noticed this too. Adding Guava makes my build take ~30s instead of ~8s. – goncalossilva Aug 18 '12 at 23:18
  • I've separated the classes I use from Guava. That helped reducing build time for me. Unfortunately, unless Guava guys decide to split the library into smaller modules, this is the only way as I see it for speeding up the development build. – AlexV Aug 19 '12 at 05:33

1 Answers1

12

For what it's worth, my gut is that this isn't the cause. It's hard to take a long time doing anything with a mere 1.1MB of bytecode; I've never noticed dex taking any significant time. But let's assume it is the issue for sake of argument.

If it matters enough, you could probably slice up the Guava .jar to remove whole packages you don't use. It is composed of several pieces that aren't necessarily all inter-related.

I don't think this is going to speed things up, but maybe worth mentioning: if you run the build through Proguard (the optimizer now bundled with the SDK), it can remove unused classes before you get to DEX (and, do a bunch of other great optimization on the byte code). But of course that process probably takes longer itself than dex-ing.

Sean Owen
  • 66,182
  • 23
  • 141
  • 173
  • I've tried to slice the classes I need out, but pretty fast found myself with 40 classes and counting, besides it's ugly :) The thing with ProGuard is that I haven't found a way to embed it in Intellij build. Thanks. – AlexV Sep 25 '11 at 20:00
  • +1 for mentioning Proguard, and it's worth even if it takes time (at least in this case) – Premraj Sep 28 '11 at 07:02
  • 1
    @AlexV: Couldn't you run ProGuard once manually to find out what classes are needed? I'd bet it doesn't get tired by counting to 40... – maaartinus Sep 16 '12 at 10:52
  • @maaartinus at the end what I did is extract the functions I use to my own classes. I know this sucks, but even after running Proguard there are too much Guava classes left. I've ended up with ~ 6 classes (Lists, Maps, Iterables, etc). – AlexV Sep 25 '12 at 12:52
  • @alex ProGuard in Idea: go to File > Project Structure > Modules > YourModule > Android > Compiler tab and check Run ProGuard. Then go to your module directory and run `android update project -p .` to generate the default _proguard-project.txt_. That's it, you have ProGuard optimizing and obfuscating your classes before they get to the DEX compiler. You can tweak what ProGuard does by modifying the _proguard-project.txt_. – SnakE Oct 22 '12 at 12:25
  • @SnakE That's cool, but I'm pretty sure this feature wasn't there a year ago – AlexV Oct 25 '12 at 07:24