Adding Dagger To Your Android Project In Eclipse

来源:互联网 发布:知我药妆是不是正品 编辑:程序博客网 时间:2024/06/10 07:57
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 libraryDagger. 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.
    • Dagger 1.10 (at the time of this writing.. check for the latest version)
    • Dagger 1.10 Compiler Jar (version number must match version of Dagger jar)
    • javax.inject
    • JavaWrite
  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).
0 0
原创粉丝点击