129

I am involved in the development of Android application which is a rather "thick" mobile client for a Web service. It heavily communicates with the server but also has a lot of inner logic too. So, I decided to use some features of Google Guava library to simplify development process. Here is a list of features I'm very interested in: immutable collections, base utils, collection extensions, functional programming sugar and idioms (common.collect and common.base), primitives utilities (common.primitives), hashing utilities (common.hash), concurrent utils (futures and AsyncFunction). Things I don't want to use in Android: common.cache (see question below), common.eventbus (we have better Android specific libs for this, such as Otto), common.io (we can use okio for Android now).

I read that using Guava for Android can significantly slow down compilation process and also decrease the whole runtime performance: Bad performance with Guava Cache on Android (in this case it is reasonable and there is no need to use Guava's cache for Android) and Adding Google Guava to Android project - significantly slows down the build

So, is it efficient to use Guava library in Android project or this library is designed to be used only for the server-side development, and I should go with standard solutions? Any explanations will be very appreciated.

7
  • 2
    "But I heard that [...]" what are your sources?
    – jlordo
    Feb 20, 2013 at 11:31
  • IMHO, there are good answers in the questions you have linked, and you are asking nothing else.
    – jlordo
    Feb 20, 2013 at 11:37
  • 2
    It's safe to use, but of course: You need to check for each class of the library if it fit's your needs. Guava Cache was implemented for Server side (which is propably written in the docs), so don't use it on android. Build time is usually not really a problem, run time is more important.
    – John Smith
    Feb 20, 2013 at 11:48
  • 4
    appbrain.com/stats/libraries/details/guava/google-guava indicates that Guava is used in a lot of Android apps. Feb 20, 2013 at 18:06
  • 3
    Shame that new answers cannot be posted (I for one voted for reopening). There are some real and interesting issues e.g. related to the 65k method limit that deserve attention.
    – Jonik
    Nov 5, 2015 at 12:15

1 Answer 1

124

(Too big for comment, so I post an answer.) Personally I use whole Guava library in every Java project and when I don't have significant and properly profiled performance problems. If you do have, for example, memory concerns like in Android environment, you can use ProGuard to get only these parts of Guava you really need.

Moreover, there are many Android apps using Guava - not only small ones, i.e. Google Search and Youtube, which directly come from Google.

(You should also see compatibility note.)

16
  • 110
    I was curious about Guava & APK size. Simple testing revealed the following: "Hello world" & not much else (debug): 27KB; "Hello world" with Guava (15.0) dependency and minor Guava usage (debug): 705KB; the same, release build, optimised with ProGuard: 22KB. This test, together with having used Guava while developing a large real-world app, confirmed my belief that Guava is totally fine on Android too!
    – Jonik
    Jan 5, 2014 at 16:15
  • 2
    Also, if you run into problems getting ProGuard to work with the Guava dependency, see this answer I just posted.
    – Jonik
    Jan 5, 2014 at 16:18
  • 2
    Just an observation on the link for top apps using Guava. I'm a heavy user of Facebook, Spotify, Google Translate and they are not the fastest apps running out there right? In fact they're bad. FB I don't need to tell you, Spotify with latest updates made me go from Premium to Grooveshark. Facebook and Spotify really struggle with user experience on mobile, and curiously I find Google Translate has slowed down a lot for such a simple thing it does. Now I haven't tried Guava. But I'll think twice before I do. This is the link: appbrain.com/stats/libraries/details/guava/google-guava Mar 12, 2014 at 12:52
  • 7
    Something to be aware of with Guava is the Android 65k method limit, as Guava lib contains over 13k methods. Reaching the limit shouldn't be a problem as you can go Multidex (but I have no first hand experience of that). See related discussion at Futurice Android best practices guide.
    – Jonik
    Aug 2, 2015 at 9:55
  • 3
    @Jonik I don't know why I don't see more people mentioning that. Sure you have proguard, but is it really worth it? What about debug builds, you'll have to run proguard on those as well. I don't consider multidexing to be a solution either. It adds easily 2-5 seconds loading time to the app. In really big projects it's not that hard to hit the 65k limit. Imo Guava is such a monolith that I'm not really a fan. I'd rather use smaller, focused libraries that bring in a specific set of functionality.
    – Joao Sousa
    Nov 5, 2015 at 11:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.