I have heard this question from junior android developers that which libraries we should learn and explore, those libraries which are being used in top applications (i.e. top application in terms of download numbers and five star rating counts).
Also those libraries which helps in i) application performance ii) clean code iii) code quality and code optimization and many other such point.
Today I will list down top libraries which are being used by experienced developers in their apps development.
1) Retrofit 2 with OkHttp3
Are you still using AsyncTask or implementing http operations with custom callbacks? If yes then I would suggest you to start using Retrofit 2.
- Retrofit is a REST Client for Android and Java by Square. It makes it relatively easy to retrieve and upload JSON (or other structured data) via a REST based webservice.
- It’s very well documented and very easy to add into the projects.
- Over Github, It’s being supported very well by community also.
- With Retrofit 2, you can use any parser to parse the network response data, one of the popular parser is GSON, to start using that you just add the converter dependency and that’s it!
These are couple of winning points over Volley library but if we compare both the libraries then both are having pros and cons.
Retrofit uses OkHttp automatically if available.
Now about OkHttp, it is an modern, fast and efficient Http client which supports HTTP/2 and SPDY. OkHttp handles the lower-level HTTP connection details, while Retrofit simplifies using REST APIs. Retrofit can be used on top of OkHttp, but it is not required.
At one point, you might get a question, why to use both the libraries? Any different? Below is a reply from Jake Wharton:
OkHttp is purely an HTTP/SPDY client. Retrofit is a high-level REST abstraction on top of HTTP. You can certainly use OkHttp with Retrofit (and I would recommend it) but it’s not required. Apache HttpClient and the normal UrlConnection will work just fine.
First of all, are you still writing findViewById() code? Or Are you bored of writing findViewById()? And setting action listeners? If yes then you should start using Butterknife, which would help you in saving your productive time by not writing findViewById() code.
If you are wondering how you can avoid is, you can eliminate findViewById calls by using @BindView on fields.
Well, to brief about Butter knife library, it is is a popular view injection library created and open sourced by Jake Wharton. It allows you to annotate the inflation of your views and OnClickListeners so that you can get back to writing the code that really matters.
Checkout Github repo and documentation, also my earlier blog post on Get more out of Butter knife.
Tip: To make writing @BindView even easier, use Butterknife zelezny plugin in android studio which helps in generating butterknife injections from the selected xml.
3) Dagger 2
Same as Butterknife is for view injection, Dagger 2 is for dependency injection. Checkout user’s guide documentation to know more about it.
You might have used Roboguice in past or if you are familiar with it then you must know it was causing performance issue and thereby it was delaying application startup time, because it was performing operations at run time. Whereas Dagger 2 iis a dependency injection framework that is built on the standard javax.inject annotations (JSR 330).
FYI Dependency injection is a software design pattern that implements inversion of control for resolving dependencies. Implementing proper dependency injection in our apps allows us to have:
- Testable classes.
- Re-usable and interchangeable components.
These are the image loading libraries, if you are still using Universal Image loader or any custom defined modules then it’s time to start using Picasso or Glide. Facebook has also released Fresco library lately.
With Picasso, you can also use the OkHttp http client. Picasso and Glide are having almost same method names and classes, so it’s really easy to change the library at any time!
But again both the libraries are having different points and usages.
- Glide provides gif loading functionality
- Glide is having more number of methods
- Glide’s library size is higher than Picasso
- Picasso caches full-size image in memory, where as Glide caches image of ImageView size (height and width of ImageView)
Read this article to visualize difference between Picasso and Glide.
I have reviewed code of many projects and I have observed many developers are still parsing json manually by writing those native classes like JSONObject and JSONArray.
Stop implementing json parsing manually, instead use Gson library and have a mechanism that it will give you POJO objects directly, and thereby it would be easier for you to access sub parameters of the json object by just accessing attributes through the POJO.
To brief you about Gson library, Gson is a standalone and open source library which is used to convert JSON data into Java objects and vice versa. In simpler words, it can be used for parsing and building JSON. Gson can work with arbitrary Java objects including pre-existing objects that you do not have source-code of. It simply provides toJson() and fromJson() methods to convert Java objects to JSON and vice-versa.
Many a time it happens your app is getting crashed but you never come to know about crash if crash report is not shared with you.
Crashlytics is a part of Fabric product by Twitter, but recently Google has acquired Fabric team so we can expect some more functionalities in coming future, but mean while start using this library to get crash reported submitted to dashboard automatically.
RxJava is a Reactive Extensions for the JVM – a library for composing asynchronous and event-based programs using observable sequences for the Java VM.
To explain you with an example, consider a scenario where you are fetching data from API, syncing it into local database. Now there is a condition when user launch app, it should display data from local database if available, and at the same time make a call to API, if new data found then sync it into database and also update UI same as what Facebook and twitter does with “5 new posts found” kind of message.
If you are aware about Observable pattern then it would be easier for you to start with RxJava. Ultimately it’s based on Observables and Subscribers concept.
I have started using these libraries combo since past 5-6 months, was using all the libraries but not RxJava but now have started using it, seeing great performance and improvements in making API calls, clean code, clean architecture, optimized code and solid improvement in performance. Choice is yours whether to start using given list of libraries! If you are inspired and if you start using given list of libraries then looking forward to hear back from you on it!
Keep coding, keep rocking!