Wednesday, October 7, 2015

MyNotes: Goodbye Guava


I have noticed a few odd build failures lately that were not due to syntax errors.  These were the java.exe failing with error code 2.  This is a big red flag that there is too  much going on library wise.   The root of the problem is that android has issues when an app has more than 65k methods.  This includes all of the libraries that get built into the app.

Guava is a huge monolithic library.  And I brought it into both my common library module and the mynotes module.  In addition, it looks like ButterKnife also brings in a Guava version.  That would be three compilations of a very large library for  very small app.

I tried doing some selective behavior with gradle to minimize the library impact, but none of them work really well and made the files very messy.  I also thought about enabling multidexing, which would also fix the problem, but that seemed ridiculous to do for a tiny app.

So that left me with analyzing whether I really needed Guava.  The short answer is no.  I am only using two classes: Preconditions and Strings.  And I wasn’t even using the majority of the methods in those classes.

As a result, I took out Guava and created my own Preconditions and Strings classes.  I kept the method and class names the same, but spun my own implementations.  I stuck those classes in the Common Library for now.

Ta Da:  weird build problems magically go away.  The moral of the story: be careful bringing in libraries unless you really need them.


The changes can be found at

No comments :

Post a Comment