Which Android Dependency Injection is best?

综合技术 2017-11-06

This post is a summary of first impressions of a few android related frameworks that we ( Tell Me How Blog ) tried out during a competences session recently.


“Dagger constructs instances of your application classes and satisfies their dependencies. ”

Dagger is a dependency injection framework, unfortunately most of us did not manage to setup dagger or failed to get dagger running once setup. So I can not give a proper overview of dagger2.

Read more: http://google.github.io/dagger/


“Annotate fields with @InjectView and a view ID for Butter Knife to find and automatically cast the corresponding view in your layout.”

Butterkife is a view injection lib for android. As such it only handles injection of view components and does this using a InjectView annotation. So some boilerplate is removed and less code has to be written. Some of us found the result a bit harder to read and in some cases the reduction of code was not noticeably, but this is most likely true for the other injection frameworks to and not something specific for Butterknife. Setup was easy with just one dependency. Stack-traces was reportedly difficult to read when Butterknife was used.

Read more: http://jakewharton.github.io/butterknife/

RoboGuice 3

“RoboGuice 3 takes the guesswork out of development. Inject your View, Resource, System Service, or any other object, and let RoboGuice 3 take care of the details.”

RoboGuice 3 is similar to AndroidAnnotations and Butterknife, easy to setup, two dependency’s needs to be added to the build file. This framework seems like it should be easy to use if you are already familiar with Guice, and even if you don’t its not that hard to understand and use. It is similar to the other dependency injection frameworks that you don’t get all that much for your money, but it’s easy to use and removes some boilerplate. The documentation could use a touch-up.

Read more: https://github.com/roboguice/roboguice

Final Verdict:

The views on the frameworks above is the result of a 3 hour session where we tried them out and had a short discussion about each of them to sum up the experiences. Given the limited time we spent on each of the frameworks we might have missed some important things, if you find and mistakes or are missing some important information please post a comment below.

Read more >> Comparison of All Android Dependency Injection


Android的设计模式-适配器模式 前言 Android的设计模式系列文章介绍,欢迎关注,持续更新中: Android的设计模式-设计模式的六大原则 创建型模式: Android的设计模式-单例模式 Android的设计模式-建造者模式 Android的设计模式-工厂方法模式 ...
放弃debug的必备命名 说在前面: 这篇文章的名字可能有点逆天吧,如遇不适,我将深感抱歉,但是绝不道歉:stuck_out_tongue_closed_eyes:问题背景: 在一次软件迭代提测时提测,信心满满的...
Android Instagram like Login screen with SQLite In my Previous on Creating Instagram like login UI screen , I explained how to achieve below UI design. In this post, let’s continue towards making o...
减小APK大小 本篇文章翻译自 Reduce APK Size 用户通常不会去下载体积过大的应用程序,特别是当自己的设备连接的是 2G/3G 或者按字节付费的网络。这篇文章描述了如何缩减 APK 的体积大小,以使得更多用户愿意下载你开发的应用。 了解APK结构在讨论如何缩减你应用的...
Keypad hide / show in webview I had tried this out. And it works fine with Samsung tablet.On Page 1_4.html i have to hide keypad and on 2.html I Have to show keypad. Both...