Thursday, September 5, 2013

on Leave a Comment

Adding Dagger to your Android project in Eclipse

Today I started messing around with different dependency injection frameworks for Android. I am a big fan of the libraries put out by Square so naturally I wanted to try out their library Dagger. Unfortunately the setup instructions are vague if you are not using maven in your project. For my purposes I just wanted to add the project to an existing (mavenless) Android project in Eclipse.

I found some steps in one of the help threads that were slightly outdated so I wanted to put out some updated instructions (with pictures) for those that came after me. In the end adding the library is very simple but there was some confusion over exactly which Jars I needed. It turns out that the dependency list for the project has grown slightly. If you miss that line at the very bottom of the projects website it can lead to an hour of frustration (maybe that is how you ended up here!).


  1. First Download the jars files required for the project and add them to your libs folder in eclipse.
  2. Now that those are added to the Libs folder we need to open our project properties and go to the Java Compiler screen. Check "Enable project specific settings"


3. Hit the little arrow on the left and select Annotation Processing". Here we need to check "Enable project specific settings" . Also make sure "Enable annotation processing" and "Enable processing in editor" are checked. 


4. Finally go to "Factory Path" and then click "Add JARs". Add all the jars you downloaded in step one to this list and make sure the little box is checked next to each one. Disregard the butterknife jar in the image below. It is another awesome square library I happened to be using in this project. 


5. Hit Apply and OK. Your application should do a clean/build and you should be good to go.  If you are just getting started with Dagger I recommend taking a look at their Android samples (after reading the documentation of course).
Powered by Blogger.