Quick summary of recent libraries to put hands on
It’s a short summary of new libraries that became stable recently. If you saw all these new libraries but you haven’t had time to put your hands on, it’s a good read for you. I created this list for myself and decided to add short comments with useful links here to save you some time.
Coroutines + Flow API
A few weeks ago, Kotlin Flow became stable in Coroutines 1.3.0 release. It’s a serious pretender to replace many RxJava usages in Kotlin apps. There are still some experimental operators but it’s a good time to put your hands on Coroutines and Flow API.
Do Coroutines with Flow seem much simpler than RxJava? They do. But if you are used to RxJava, I’m sure that getting used to Coroutines will take you some time. Especially if you want to learn how to test them (already covered in many tutorials). That’s why in most cases I would not recommend you to implement it straight into a commercial project. It’s a good idea to block a few hours to test them in a pet project.
Check out this series of articles about Kotlin flows: Cold flows, hot channels article. Keep in mind that both Flow and Coroutines are available only in Kotlin.
The motive of Koin is clear. Developers were pissed off by the complexity of Dagger and fell in love with the simplicity of Koin. But is Dagger really complex? Well, you can set it up easily. But there are a few ways of using Dagger and it depends on a version. So as long as you set DI up using a tutorial, you can copy-and-paste your modules and everything works! But then if you want to inject something to, for example, Worker from WorkManager, you have to copy-paste and test 5 versions from StackOverflow until it works with your dagger version. That’s irritating if you don’t know how your version works.
I think that the real problem of Dagger were old docs. Of course, now you can learn easier because Dagger has updated docs without Thermosiphons.
Koin as alternative
Koin2 became stable a few months ago. I’m sure that many people haven’t tried it yet. Why? It has drawbacks too. Koin is slower and it doesn’t have compile-time validation. Of course, it’s not an issue in smaller projects. If you can’t or don’t want to write service locator yourself, Koin is usually a good choice.
In fact, many small projects don’t even need Dagger, RxJava, Room, multiple modules, yet they use them. It’s like wearing a tuxedo to throw away the garbage.
I have an impression that it’s the same case as with ObjectBox or Navigation Component. You give away some flexibility for simplicity.
By the way, Koin has good documentation too.
Also, Koin is not a dependency injection library but a service locator.
SQLDelight is not a slightly improved Room. It’s a library built on a different layer of abstraction than Room. It allows you to write SQLite queries and access them through generated Kotlin code. Why is so? There are many resources that explain it but my favorite is The Resurgence of SQL. It’s a great data persistence overview that also explains the advantages of SQLDelight.
Moshi is like a new version of GSON created by its main contributor who escaped from Google. That’s why it has a new name. I don’t think that you should migrate to Moshi in all of your projects but it’s a good idea to use Moshi in new projects. Check out Reddit discussion Why use Moshi over Gson and secret documentation nobody knows about.
If you don’t like navigation to handle back stack yourself and you’d like navigating to be as easy as possible- give it a try. Navigation component handles nested fragments and fragment transactions well for you. That makes it really suitable for MVVM apps with a bottom navigation bar.
Of course, it has some drawbacks. Make sure to read this Reddit discussion about multiple back stack issue.
On the other hand, if you hate XML or if you simply don’t have 64GB RAM to open XML layout editor, try Contour. It’s a programmatic way of creating dynamic layouts. Although I like Constraint Layout a lot, why don’t you check out Reddit discussion about pros and cons, what it is and what it’s not?
I almost forgot about this library and it would be a pity. Coil is a lightweight image loading library that leverages Kotlin language (It’s Kotlin-first). That’s why it’s a really practical library that you should consider in the future. Check out the repository. Also, if you are a benchmark guy, check out a performance comparison discussion.
Balloon is a unicorn here. After using libraries above, your codebase will look perfect for at least 3 months. But what about your UI? Well, this library lets you customize cool pop-ups. It’s lightweight, it has nice animations. Customize your pop-ups using builder pattern or Kotlin DSL (so the implementation looks tidy as well).
I know that pop-ups seem insignificant but pop-ups are often overlooked in designs. And without Balloon, nice custom ones are tedious to implement. Don’t overlook details and check the repository.
Lot’s of new libraries. Is using each of them in existing projects worth it? I don’t think that forcing all of the new libraries is worth it. But for sure it’s a good idea to consider them in new projects or migrate thoughtfully in existing projects.
By the way, If you want to be notified about more articles like this one, subscribe below.