(This post is now outdated. Check out The Top 10 libraries as of August 2019)
There comes a time in every Android Developer’s blog where they have to talk about LIBRARIES.
Not just any libraries, but the libraries that you’ll see as an essential on pretty much every job you’ll be applying for. Even if this ain’t the case, it’s undeniably that these are the libraries that will help you out insanely in your development career.
These libraries go from reducing boiler plate code, simplifying complex algorithms, defining the flow of your app, analytics, testing, it just goes on man. These libraries are going to be more general purpose ones that can fit into almost any app
10. ButterKnife
If you’re writing in Java and you’re not using this ButterKnife, you’re doing it wrong. It turns this:
TextView tv1; ImageView iv1; ImageView iv2; private foo() { tv1 = findViewById(R.id.tv1); iv1 = findViewById(R.id.iv1); iv2 = findViewById(R.id.iv2); }
Into this:
@BindView(R.id.tv1) TextView tv1; @BindView(R.id.iv1) ImageView iv1; @BindView(R.id.iv2) ImageView iv2; private foo() { Butterknife.bind(this); }
ButterKnife shortens your code tremendously, and not just with findViewById. It helps with ViewHolders, OnClickListeners, Resource Lookups, the list just goes on.
Link: http://jakewharton.github.io/butterknife/
9. LayoutManagerGroup
This list won’t be complete without something on the front-end.
LayoutManagerGroup simply gives you more LayoutManagers you can use with your RecyclerViews to get your app looking fabulous.
Link: https://github.com/DingMouRen/LayoutManagerGroup
8. LeakCanary
LeakCanary does one thing and it does it damn well: it detects memory leaks in your app. When memory leaks, your app freezes for a moment, and nobody wants this. LeakCanary traces the leak and helps you find the root cause making it easy for you to make the changes that boost your app’s performance.
Link: https://github.com/square/leakcanary
7. Roboelectric
If you’ve done any TDD with Android before, you’d know that unit tests just…. they’re just no. Running one on the JVM is useless because it only implements stubs of the Android SDK classes, and running them on an emulator is slow af.
Roboelectric allows you to run your unit tests on the JVM with proper implementations of the Android SDK.
Link: http://robolectric.org/
6. Parceler
@Parcel class ListItem(var id: String?, var name: String?, var count: Int) { constructor(): this(null, null, 1) }
intent.putExtra("listItem", Parcels.wrap(listItem))
A parcelable class with Parceler
We’ve all been there. We’ve got some non-standard data that we need to wrap up and send to other Activities but Serializables aren’t working and Parcelable are an absolute pain to write. Parceler makes it so that one little @Parcel annotation in your custom class turns it into a Parcelable! It gets especially simple if you’re writing in Kotlin!
Link: http://parceler.org/
5. Dagger 2
public class ScheduleActivity extends Activity { @Inject ScheduleManager scheduleManager; public void onCreate(Bundle savedInstance) { InjectorClass.inject(this); }
Injecting an instance of ScheduleManager into ScheduleActivity
One of the harder libraries in this list to understand, it is definitely one of the most powerful as well (and also endorsed by Google). In a regular app, we write classes that depend on each other, like say, if you have a ScheduleActivity and a ScheduleManager, and the activity obtains an instance of ScheduleManager. ScheduleActivity is dependent on ScheduleManager.
Dagger cuts the dependence between these classes and redirects the instance of ScheduleManager to the Dagger object. Dagger will then “inject” an instance of ScheduleManager into ScheduleActivity. Like a company trying to outsource developers. It can outsource them directly, or it can go through an agency (which would be Dagger) to make things easier.
What purpose does this serve you may ask? It isolates ScheduleActivity from ScheduleManager, allowing you to unit test ScheduleActivity and individual changes to ScheduleManager won’t require you to make corresponding changes to ScheduleActivity. What if 12 different classes use ScheduleManager? Maintaining that without Dagger would be a right pain.
Link: https://google.github.io/dagger/
4. Glide
If you’re working with images at all in your app, just use Glide. It’s officially endorsed by Google. They use it a lot, and for good reasons. Glide optimises the loading of images immensely (their goal is to let you scroll down lists of images as possibly smooth as it can get).
Glide .with(myFragment) .load(url) .centerCrop() .placeholder(R.drawable.loading_spinner) .into(myImageView);
Loading an image with Glide to an ImageView
Glide also lets you do more complex image stuff through a simple interface like fetching, decoding, displaying video stills, you know.
Link: https://github.com/bumptech/glide
3. Retrofit
public interface GitHubService { @GET("users/{user}/repos") Call<List<Repo>> listRepos(@Path("user") String user); }
Making an API Call with Retrofit
API calls are an essential to many apps, but boy they can be a pain to write. Not with Retrofit though. Once you set it up in your app, making API calls is as simple as one or two lines in an interface.
Link: http://square.github.io/retrofit/
2. RxJava
The golden boy, RxJava himself. If you’ve been tuning in, you’d know I’ve been talking about RxJava a lot going into this year. EricDecanini 2019 Boys!
RxJava is Java (and Androids) version of React. It lets you transform almost anything your app does into an asynchronous event-based program through observable sequences (quoted from the boys themselves).
// getUser is a network call that can take time listService.getUser() .subscribe { user -> // Subscribe will wait for getUser to resolve then do: doStuffWithUser(user) } }
Performing getUser using RxJava. Note that a callback is avoided and replaced with a subscription.
While it doesn’t have the easiest learning-curve, this library provides numerous benefits which increase with your proficiency with the library. Some benefits include increased app modulation, multithreading (for peak app performance), graceful error-handling, avoiding callback hell, manipulating your data streams extensively, and just cleaner and more concise code overall.
Learning RxJava is probably one of the best things you can do as an Android Developer and it is a library that can fit into pretty much any app.
Link: https://github.com/ReactiveX/RxJava
1. Firebase
You may have guessed it boys! The main topic of the blog itself, Firebase takes the #1 spot! And let me tell you why.
For those of you who don’t know, Firebase is a package of over 20 different Cloud Services. Most of the platform is free to use on a small scale and it’s piss-easy to learn pretty much all of them.
This means new developers have a way of implementing features like Cloud Database, Authentication, and Cloud Storage in their app at an easy learning-curve and the cost of a whopping £0!
While the learning curve is pretty low, Firebase does have a steep mastery curve which lets you exploit its numerous features even more as you get better at it. In fact, here’s a list of some of its features:
What’s more is that Firebase is not only endorsed Google, but its developed by Google themselves. The people in the Firebase team are very friendly, people I’d personally like to get a bit closer to and probably meet somewhere down the line. They have their own YouTube channel (though a cringe-fest at times) and hold a Firebase Dev Summit every year at different places in Europe.