Photo by Jefferson Santos on Unsplash

Imagine having to copy and paste the same code in different application over and over again or having to browse through stack overflow posts thinking a fellow developer has done this already. A library is a set of classes and methods that can be reused in different projects. Libraries have the ability to massively impact your application by allowing you to include complex features and reduce boiler plate code with ease. Common Android Libraries include: Android Support Library, Firebase Job Dispatcher Library and Google Play Services just to name a few.

Android Support Library

The most common library in Android is the Android Support Library. The main purpose of this library is to provide backward compatibility for new features of Android so that you don’t have to write different codes for different API levels. The support library is very large, including the entire library in your app when all you want is a just a part of it is an overkill to your app. Hence the Support Library is fragmented into many different packages based on functionalities. So that you can include only the features your app requires and for easier development and support across more devices.

Finding Libraries

Libraries are useful for solving problems that appear over and over again in different applications. Two resources for finding libraries include Android Arsenal, which is a large collection of libraries that just about anyone can add to. There are literally thousands of libraries on it ,of highly varied quality. The second resource is this GitHub page, which lists some of the most commonly used android libraries.

A word of caution: just because there is a library that seems like a perfect fit for your need, do not be too hasty in adding it to your application. Using a library that is not well maintained or documented comes with a host of other issues and is likely to cause more of a headache than it cures.

Another consideration in deciding whether or not to use a library is to be aware of how it will affect the size of your app. When your app, including the libraries it uses, reaches a certain size, you encounter build errors that indicate your app has reached a limit of the Android app build architecture (64K Method Limit).

Choosing a Library

There is no cut and dry way to determine the best fit for you application but below are a few things to consider:

Maintenance: Android is constantly evolving and the library that you choose should evolve with it. A lot of libraries stop working when a new version of Android is released and so will your app if uses such a library. Further, you need to check who is doing the maintenance. If is an individual who might have lost interest along the way or deprecated the library. Or is it a company dedicated to maintaining a high quality code over a long period of time.

Known Issues: Many libraries have issue section on their GitHub page where users of that library can submit problems they are having with it. Check this section to ensure there aren’t any problems that will affect your app.

Features: Often there are several libraries that perform similar tasks. In this case, choose a library that best fits your app requirements without a tone of extra functionality that will only increase your APK size.

License: Check the license of the libraries you are going to use for the specific requirements in your application. Failure to comply with some licenses can result in your application being rejected and potentially some legal trouble.

Lastly, a useful trick for making sure a library is a good fit is running a Google search on the name of the library followed by the word versus. This should result in a list of similar libraries with comparisons of features.

Must Have Libraries

Picasso and Glide: A common problem that Android developers face is the proper use of images in their application. Including many high quality images will drastically increase your APK size, while downloading images over the network comes with memory consumption and network availability problems. Picasso and Glide are both very robust libraries that facilitate the loading, caching and displaying of Images. They include tons of amazing features, such as the ability to include placeholder images and local caching, so almost every application that includes images uses one of these libraries. Check out the documentation on Picasso and Glide.

Butterknife: If you’ve created an app with a lot of views, then you’ll know how tedious it can be to write findViewById () calls for each one, as well as to create custom onClicks for each one. These tasks pertain to Data Binding, the realm of connecting your data to the user facing views. Butterknife is a revolutionary library that uses annotations to make this much easier. Check out the documentation for some examples of how this can make your life much easier. Check out this code branch to see how it would look like.

Timber:

Created and maintained by the same developer who created Butterknife, Timber is a really cool tool for Logging. I’m sure you have all used the built-in Logger and know the importance of seeing information about your app in the debugger. Timber takes this further by providing a modifiable platform for all your logging needs. It contains these and many more features:

Log without a TAG (Timber creates one for you)

Create different logging logic for Debug and Release version of your app (you probably only want to see errors in the release version)

Automatic error detection

See this library in action in this code branch.

Conclusion

There are a lot of amazing libraries. Go on and use them to resolve your problems but make sure to credit them. Just remember that if it’s a common problem then some one has most likely made a library for it. If not then why not make one yourself. Here is how you can create an android library.