Some time ago I wrote the Pay It Square (http://www.payitsquare.com) Android application for a couple friends as a way to promote their service on the Android platform. Prior to this while I had done Java programming in the past it was not of the “advanced” variety, at least not as high level as what I do in .NET. This being the case it was my first true exposure to DI in Java.
For DI on Android we used RoboGuice (https://code.google.com/p/roboguice/) which allows for various forms of injection to assist the Android developer in developing the common boilerplate code (ie: getting a reference to a view in a related layout).
For my upcoming talk on Push Notifications talk I wanted to create the Android demonstration app using this tool. Having been a while since my last big foray into Android I noticed that RoboGuice had recently been updated to version 2.0. No problem, the instructions (https://code.google.com/p/roboguice/wiki/InstallationNonMaven) seemed clear enough. However, I quickly found out that something was wrong.
After adding the files as Jar references and then as Library references I kept getting an error relating to the Provider and Class Not Found. At first I thought I was not referencing the Jar files correctly in IntelliJ. However, this was not the case.
After breaking things down to their simplest form, I found that a certain Jar file that I thought I had (courtesy of the RoboGuice download) was in fact not correct. The answer to solving this was to download the files separately:
- guice (no aop) – http://bit.ly/VXOLsb
- roboguice – http://bit.ly/WWBPyR
- javax inject – http://bit.ly/14KutBD
The problem child here is the javax inject library which supplies the ability for guice to “inject”. The link above references a ZIP file which contains the javax.inject.jar file. Add all three of these JAR files as Library references within IntelliJ and everything should work fine. Leave comments if they dont.
One thought on “Using Guice in your Android project”
Nice post.Give it up. Thanks for share this article. For more visit:Web App Development