Does it make sense to use Guice for Android

Otto picture Otto · Oct 18, 2011 · Viewed 11.7k times · Source

I'm debating using guice in an android project that is quite complex and has a lot of business logic. Guice seems like a good fit, but whenever I start reading deeper into it, it starts to look more complicated than it needs to be.

One thing I don't understand is: if Guice is so great and the best way to write java code, how come there is so little Android code that uses Guice... and why didn't Google use guice internally for Android?

Answer

Manfred Moser picture Manfred Moser · Oct 18, 2011

Guice totally makes sense to be used and in fact is used in a whole bunch of applications. The extension RoboGuice adds some niceties for Android that makes it super productive to use.

In fact I can not imagine writing an Android app without it. Too painful.

Check out the links to apps using Roboguice on the website (e.g. Google Docs, OpenTable...). Also other apps like the Square app are known to use Guice directly.

It totally makes sense .. go do it!

Together with Robolectric it will also make your testing efforts easier.

PS: I am a committer on RoboGuice so I am partial ;-)

PPS - June 2013: Recent developments have given rise to other annotation/dependency injection based frameworks that do most of the work at build time and therefore avoid the performance hit of the runtime reflection (that is slow on Android) and are therefore more suitable for performance critical work - check out Dagger and AndroidAnnotations if you are interested in that.