Tagged with: font rod next down source GOOGL Android developer Extra
Right Now there are two versions of Dagger, one for square dagger1.x and the other for Google-led and Squre jointly developed DAGGER2.
This article describes the setup of dagger and Dagger2 usage environments in eclipse. Examples are used by the dagger and Dagger2 official "coffee" case (dagger1.x case location in the Example/simple directory. The case of Dagger2 is located in the Example/simple directory).
dagger1.x:
1. First download the relevant content of dagger1.x.
Jar files can be downloaded from http://square.github.io/dagger/, please note that Dagger.jar and Dagger-compilejar all two files need to be downloaded, two jar files are currently the latest version is 1.2.2.
Dagger's full source and official example are downloaded from Https://github.com/square/dagger.
2. Additional two jar files need to be downloaded: Javawriter-2.2.1.jar and Javax.inject-1.jar.
3. Create a new Java project in Eclipse. Create a new coffee package under the SRC directory and copy all the. Java source files from the official case (example/simple) to the coffee package.
4. Create a new libs directory. Copy the 4 jar files into Libs and build path.
5. Next, change the Java compiler for the Java project. The detailed method is:
I. Right-click the Java Project. Select the following properties in the pop-up menu
II. Select Java complier. Make sure that Java is using 1.6 or more version numbers
III. Expand Java complier, select annotation processing, and select the three selection boxes at the top of the right. Enable projectspecific settings, enable annotation processing, and enable processing Ineditor
Iv. Expand annotation Processing and select the factory Path inside.
V. Click Add Jars...button on the right side to add the 4 jar packages under the project's Libs directory.
Note that the first Org.eclipse.jst.ws.annotations.core is the one that eclipse has joined. What we need to do is to add an additional 4 jar files to come in.
With the above 5 steps, the Java complier setup is complete.
6. Right-click to execute Coffeeapp.java.
After successful execution, output such as the following on the console:
Dagger 2
1. First download the relevant content of Dagger2. The jar file can be downloaded from http://search.maven.org/#search |ga|1|g%3a%22com.google.dagger%22. Please note here that in addition to downloading the Dagger.jar and Dagger-compile.jar two files. You will also need to download Dagger-producers.jar. The latest version of the first two jar files available for download is 2.0.1. The latest version of dagger-producers available for download is 2.0-beta.
Dagger2 's full source and official example are downloaded from Https://github.com/google/dagger.
2. Additional two jar files need to be downloaded: Javax.inject-1.jar and Guava-18.0.jar. It is particularly important to note that the version of guava, the guava version used in conjunction with Dagger 2.01, must be selected 18.0.
3. Create a new Java project in Eclipse.
Create a new coffee package under the SRC directory and copy all the. Java source files from the official case (example/simple) to the coffee package.
At this point, eclipse will have a build error message pop-up. Just click OK to do it. The error is due to the fact that the Java Complier has not been set yet. After the setup is complete, everything is fine.
4. Create a new Libs directory, copy 5 jar files to Libs and build path.
Note that if you are developing Anroid code, the Android SDK does not include javax.annotation-related content, and Dagger2 uses some of the classes in it when it proactively generates annotation-related classes. So when developing Android programs. You need to import an additional Javax.annotation.jar file (yes: http://www.java2s.com/Code/Jar/j/Downloadjavaxannotationjar.htm)
5. Next, change the Java compiler for the Java project. The detailed method is:
I. Right-click the Java Project. Select the following properties in the pop-up menu
II. Select Java complier, and make sure Java is using the 1.6 or later version number
III. Expand Java complier. Select annotation processing and select the three selection boxes at the top of the right side. Enable project specific settings, enable annotationprocessing, and enable processing in editor
Iv. Expand annotation Processing and select the factory Path inside.
V. Click Add Jars...button on the right side to add the 5 jar packages under the project's Libs directory.
Note that the first org.eclipse.jst.ws.annotations.core is that Eclipse has joined, and what we need to do is to add an additional 5 jar files to come in.
Pass the above 5 steps. The Java complier setup is complete.
6. Right-click to execute Coffeeapp.java. After successful execution. Output such as the following on the console:
At this point, the environment for dagger1.x and Dagger2 was completed in Eclipse. Next you will be able to refer to the official case and instructions for code learning. As to whether to choose dagger1.x or Dagger2 is a matter of opinion, there are more similarities between the two. but also different. Firstly, the performance of Dagger2 is improved, followed by a slightly different approach in the descriptive narrative of the right type injection. Dagger2 relatively brief, and Dagger2 to dagger1.x some improvements, making Dagger2 in the development of Android can be more convenient to use. On the whole. Both Dagger2 and dagger1.x functions are very powerful, but in order to get a pleasant injection effect, the descriptive narrative before injection is more troublesome. So. In Android development. Suppose, however, that you want to get the View object, event listener through annotations, omitting the writing of template-style code such as Findviewbyid and Setonclicklistener. A more targeted framework should be chosen, such as Butterknife (Butterknife's use can be used to take a look at this article: http://stormzhang.com/openandroid/android/2014/01/12/ android-butterknife/), Xutils viewutils (Xutils's use can refer to the Demo sample Https://github.com/wyouflf/xUtils in the official documentation), etc.
Build dagger and Dagger2 usage environments in eclipse