Popular searches
//

Must-have libraries for Android

11.1.2017 | 3 minutes reading time

There are a few libraries for Android, which implement a lot of widely used features and concepts from the well known Java ecosystem for less powerful devices. Some of then provide the base for my Android technology stack, which I would like to present today.

Android Annotations (http://androidannotations.org )

Android Annotations provides a whole lot of features, which really provide value for the developer in terms of readability and maintainability. The main features are:

  • Dependency injection
  • Event handling
  • Simple threading
  • Consuming REST APIs

Android Annotations uses APT and generates optimized classes at compile time. This was a design choice to reduce the launch time (respectively don’t increase it) at startup and prevent sluggish runtime behavior. It’s simple to include in your build.gradle files (both the app’s build.gradle and the project level build.gradle):

build.gradle (Projekt)

build.gradle (App)

Vanilla Android

Android with Android Annotations

When Android Annotations provides to much features which are not used, one can use a combination of Butterknife (view injection, http://jakewharton.github.io/butterknife), Dagger (dependency injection, https://google.github.io/dagger) and Retrofit (REST client, https://square.github.io/retrofit).

EventBus (http://greenrobot.org/eventbus )

To decouple an Activity or Fragment from the business logic, it may be worth to have a look at the publish/subscribe pattern and an established library called EventBus from greenrobot:

build.gradle (App)

Other steps, like publishing an event and subscribing to it, can be found in the EventBus documentation at GitHub .

IcePick (https://github.com/frankiesardo/icepick )

IcePick reduces the boilerplate code which arises as a result of having to manage instance states from activities and fragments. This is accomplished by by the means of APT and code generation (remember Android Annotations?).

The content of exampleText will be restored on all configuration change events (i.e. OrientationChanges).

LeakCanary (https://github.com/square/leakcanary )

Memory leaks are not a harmless crime! In order to find them you can use the library LeakCanary, which – once it is initialized in the Application implementation, shows a notification when it discovered a memory leak while testing the debug build.

Espresso (https://developer.android.com/topic/libraries/testing-support-library/index.html#Espresso )

Espresso is a test framework included in the Android test support libraries. It provides a DSL for automated UI tests. The implemented concepts (based on JUnit, JUnit TestRules, Matchers) are well known to developers, so this framework should be easy to learn. Espresso runs on emulators and real devices.

Conclusion

This is just a small, selected list of libraries, which focusses on code quality, maintainability and testability.
A few rough edges, which sometimes make Android development so cumbersome, are smoothed over.
Praise the community!

Which libraries are you using? Leave a comment and discuss this article with me.

//

More articles in this subject area

Discover exciting further topics and let the codecentric world inspire you.