Tag Archives: dependency injection

Indispensable Android Libraries

With recent surge in adoption of the new Gradle-based Android build system, it’s easier than ever to incorporate Android library projects (and libraries in general) into your project. Gone are the days of complex pom files, submodules, forked repos, a huge libs folder or worst of all, copying code as-is into your repo (you never did that, right?). Now a full Android library or utility can be included with a one-line addition to your build.gradle file. Here are a few that I find extremely useful in my day to day work. Continue reading Indispensable Android Libraries

DI on Android Without the Startup Cost: dagger

Anyone who has used a dependency injection (DI) framework on a project can likely speak to its benefits when creating complex systems. Relying on it can help an engineer to design and implement clean, testable software.

Anyone who has tried to write Android applications using a DI framework has likely been disappointed in some degree with current offerings. DI frameworks in Java have largely been written with server architectures in mind and as such are either generally too resource heavy to work on a mobile device. There have been some success stories, but they come with issues of their own. RoboGuice, the Android DI go to, is built around Google’s Guice. Roboguice is easy to set up and very powerful, but it comes with a cost. Because it uses run-time validation of the dependency tree, any application that uses it incurs a startup cost the first time it requests injection. On simple projects with few injected dependencies, this may be less than half a second, but I have seen it go as high as 1.5 on the latest hardware with more complex apps. There are ways to delay this cost or minimize the impact it has on the user experience (another post for another time), but the cost won’t go away.

Enter dagger: Continue reading DI on Android Without the Startup Cost: dagger