Which Kotlin libraries should the Android application developer use? Which Kotlin libraries are better, more useful and practical?
These two seemingly simple questions may be the concern of every Android app developer. A developer may not be able to use all libraries. So he has to choose among the libraries based on his needs in programming. There is a lot of discussion about this topic in the forums and specialized blogs of Android developers.
Various lists, with different titles such as Most Useful Kotlin Libraries or Kotlin Libraries Every Developer Should Know, are also suggested in those specialized forums. In this article, I also tried to introduce the most useful Kotlin libraries to you. Before introducing the libraries, I will explain the criteria for selecting the Kotlin libraries to introduce in this article.
Table of Contents
Kotlin libraries for Android development
Kotlin is developed by JetBrains (a Polish software development company). If anyone wants to know Kotlin, besides the official Kotlin website, they should also read the Kotlin blog at JetBrains. Therefore, it can be argued that there are two reference sites for Kotlin. Both of these sites talk about Kotlin libraries and introduce libraries. My basis for choosing the following libraries was primarily these two reference sites.
If you visit the Documentation section of the Kotlin site, you will find this title in the menu on the right side of the page: Official libraries. Under this title, 3 libraries are introduced: Kotlinx.coroutines, Kotlinx.serialization & Ktor. Of course, Ktor is a Kotlin framework (it’s off topic after that). In the JetBrains blog, in addition to those official libraries, 3 other libraries are introduced: Multik, Viktor & Kotlinx.datetime. Another interesting library (MockK) has been developed for Kotlin, which is used by Android developers. I will give explanations about it.
I’ll start with the official libraries.
1. Kotlinx.coroutines
Basically, the parallel execution of several tasks without interrupting the main flow (main thread) of code execution is one of the challenges of programming. For this reason, in programming for the site or application, Asynchronous Programming is considered an important issue. Various solutions have been proposed to solve this challenge. One of these solutions is coroutines. Different languages such as C, Java, Ruby, and Python & Kotlin use coroutines. In most languages that support coroutines, this is done through the language’s libraries. Kotlin has delegated this work to its most important and richest library: Kotlinx.coroutines. With coroutines, parallel execution of several tasks in the application is possible. Also, coroutines are very compact and lightweight.
2. Kotlinx.serialization
One of the other important discussions in programming is converting information into different languages so as to enable their exchange between different systems. Sometimes it is necessary to convert the information used by the Android application into another format so that it can be transferred to another system or stored in a database or file. This process of changing data format is called serialization.
The opposite of this situation can also happen: Deserialization, where data from an external source must be converted so that the application can read it. This change of formats is very necessary for applications that exchange information with a third party system. The Kotlinx.serialization library, which is a collection of libraries, performs these two data conversions in Kotlin. Kotlinx.serialization libraries enable data conversion into JSON, Protocol buffers, CBOR, Properties & HOCON formats.
3. Multik
This library is supposed to facilitate the work of Android app developers with multidimensional arrays (Multidimensional Arrays) in Kotlin. Arrays are used to collect multiple values in the form of a variable. In Kotlin, you can have two-dimensional, three-dimensional and multi-dimensional arrays.
As the dimensions of the array increase, working with it becomes a little more difficult and complicated and requires calculations. If the developer wants to perform mathematical operations and mathematical calculations on multidimensional arrays, the work becomes difficult and complicated. The Multik library makes it easier, faster, and lighter to construct arrays (up to 4D) and do the various things that can be done on them.
4. Victor
This library, developed in the JetBrains research department, is dedicated to making it easier to work with arrays in Kotlin. Viktor is an open source library. This Kotlin library is supposed to optimize mathematical calculations related to arrays and probability arrays. Probability arrays are used in Kotlin to implement models related to machine learning.
5. Kotlinx.datetime
The last Kotlin library I introduce here is made to make working with times and dates easier in Kotlin. This library is multi-platform and to work with it you must have installed Kotlin version 1.5.0 and above. An important feature added in the latest version of this library is its compatibility with Kotlinx.serialization. This Kotlin library has its own types to represent time and date. The important thing about these types (data) is that a special serializer is defined for most of them, and the developer can easily use these two libraries together.
6. MockK
This open source library was created by a developer named Oleksiy Pylypenko in 2018 for Kotlin. The work of this library is similar to Mock IELTS tests. With the help of this library, testing different functions in the application is simulated. The main task of this library is to separate the component whose performance is to be tested from other dependent components. In fact, the MockK library makes it easier and more efficient to test components in Kotlin.