Skip to content

Top 10 Essential Android Developer Libraries February 2020

It’s that time of the year when we round up the 10 best and most used Android developer libraries of the season.

The libraries listed down here have become set in stone as must-learns if you want to be a competent Android developer. Many companies will hands down require you to know many of these.

With that in mind, if you’ve spent any time Android developing at all, you’ll probably have already heard most if not all of these.

Without further ado, let’s get started with the list.

10. Android KTX

val combinedArraySet = arraySetOf(1, 2, 3) + arraySetOf(4, 5, 6)

val user: LiveData<User> = liveData {
    val data = database.loadUser() // loadUser is a suspend function.
    emit(data)
}

Android KTX further extends the high levels of conciseness and beauty provided by the Kotlin programming language which is now not even arguably, the main language of Android.

This library provides a wide range of utility functions to shorten the syntax required in everyday development code including Collections, Fragments, and LiveData. It even ‘shortens’ syntax for other libraries in this list as well, those being Room, RxJava, and Firebase.

Link: https://developer.android.com/kotlin/ktx

9. Timber

Timber.d("THIS IS A TIMBER DEBUG MESSAGE")

Timber is the ultimate logging tool that makes debugging a whole lot easier.

It provides a way to make logs without the need to manually add a log tag. Each log will figure out what class it’s being called from and use that as the log tag.

Each log belongs to a tree and no tree is installed by default because in the words of Jake Wharton: every time you log in production, a puppy dies.

Link: https://github.com/JakeWharton/timber

8. RxJava

fun observeUsers(): Disposable {

    return observeConfiguration()
            .observeOn(Schedulers.io())
            .flatMap { apiService.observeUsers() }
            .subscribeOn(AndroidSchedulers.mainThread())
            .subscribe(
                 handleUsers(it),
                 handleError(it)
            )
}

Undoubtedly one of the most widely used reactive streams in Android, this library is crucial to add to your toolbelt if you want to be a competent Android developer.

It offers the ability to use observable streams to deliver async functions with insane levels of data manipulation and control through the use of thread-switching and transformation functions.

The only reason it’s so far-down in the list is that it’s no longer the ironclad ruler in what it does. Coroutines and LiveData now provide a much more lightweight and easier-to-learn way of writing asynchronous code.

But despite even that, the sheer number of operators and observable types make RxJava superior in many situations, earning it its spot in the list.

Link: https://github.com/ReactiveX/RxJava

7. Firebase

Firebase is a set of tools to offer you almost everything you need from the cloud. This goes from typical cloud structures like a Realtime Database, Storage, Authentication, Crashlytics, and Remote Configuration, to more marketing related tools like Analytics, A/B Testing, and Cloud Messaging.

It also includes some pretty gimmicky tools like User Predictions, ML Kit, and Cloud Functions which can be extremely powerful in the right hands.

This is an indie developer’s dream as most of these tools are free until a certain timely quota for each of these services is reached (e.g. 50k database reads/day). Even after that, Firebase provides pricing plans which are pretty flexible to your use case.

Link: https://firebase.google.com/

6. Fresco

<com.facebook.drawee.view.SimpleDraweeView
    android:id="@+id/my_image_view"
    android:layout_width="130dp"
    android:layout_height="130dp"
    fresco:placeholderImage="@drawable/my_drawable" />

Glide is an amazing image loading library, but Fresco takes the win here due to how easy it is to use.

You use a special Fresco SimpleDraweeView in place of an ImageView in your xml. Here, you set a placeholder image to display while your image is loading.

In your code, you simply have to call setImageUri and Fresco does the downloading, displaying, caching, and memory clearing of the image for you.

Fresco also provides other related features such as progress bar, resizing, and even images in notifications.

Link: https://github.com/facebook/fresco

5. Room

@Dao
interface UserDao {
    @Query("SELECT * FROM user")
    fun getAll(): List<User>

    @Insert
    fun insertAll(vararg users: User)

    @Delete
    fun delete(user: User)
}

Room is an abstraction layer over SQLite which allows you to perform database queries in a similar fashion to Retrofit, using an annotation-based interface class and standard SQL syntax.

Room is also an ORM (Object Relational Mapping) library, thus handles the mapping of database objects to Java objects, allowing you to avoid the great amounts of boilerplate needed for mapping when using standard SQLite.

On top of this, Room also works with LiveData and RxJava observables.

Link: https://developer.android.com/training/data-storage/room

4. Moshi

class CardAdapter {
  @ToJson String toJson(Card card) {
    return card.rank + card.suit.name().substring(0, 1);
  }

  @FromJson Card fromJson(String card) {
    if (card.length() != 2) throw new JsonDataException("Unknown card: " + card);

    char rank = card.charAt(0);
    switch (card.charAt(1)) {
      case 'C': return new Card(rank, Suit.CLUBS);
      case 'D': return new Card(rank, Suit.DIAMONDS);
      case 'H': return new Card(rank, Suit.HEARTS);
      case 'S': return new Card(rank, Suit.SPADES);
      default: throw new JsonDataException("unknown suit: " + card);
    }
  }
}

Moshi the definitive JSON adapter of 2020. It has plenty of advantages over Gson and Jakson.

You have qualifiers like @HexColor int for multiple JSON representations for a single Java type, predictable exceptions with IOException and JsonDataException (Gson’s exceptions are all over the place), and JsonAdapter.failOrUnknown() to reject unexpected JSON data, just to name a few.

Custom type adapters are also much easier to write with Moshi with their @ToJson and @FromJson annotations.

You get all this in a library that is smaller than JSON and less prone to leaking.

These details were sourced from this Reddit page.

Link: https://github.com/square/moshi

3. Every Major Testing Library

@Test
fun `When cart total is over fifty return free delivery method`() {
    val mockCartManager = mock(CartManager::class.java)

    `when`(mockCartManager.getCart()).thenReturn(Cart(testItems))

    val actualDeliveryMethod = DeliveryManager.getDeliveryMethod(mockCartManager)
    val expectedDeliveryMethod = "free_delivery"

    assertEquals(expectedDeliveryMethod, actualDeliveryMethod)
}

The testing scene in Android is already very well defined by 4 libraries: JUnit, Espresso, Mockito, and Robolectric.

JUnit and Espresso are included in every Android by default and are responsible for running unit tests and UI tests respectively. Mockito is used for mocking and spying classes during unit tests, and Robolectric lets you access Android SDK components in unit tests for a more instrumented type of test.

While each developer/team may have slight variations in their test setups, such as using PowerMock, or whether they approve of Robolectric or not, you can’t deny these 4 are crucial to the testing scene and won’t be going anywhere anytime soon.

Links:

https://junit.org/junit5/

https://developer.android.com/training/testing/espresso

https://github.com/mockito/mockito

https://github.com/robolectric/robolectric

2. Dagger

@Module(includes = [LoginModule.LoginAbstractModule::class])
class LoginModule {

    @ActivityScoped
    @Provides
    internal fun provideResourceProvider(context: LoginActivity): BaseResourceProvider {
        return ResourceProvider(context)
    }

    @Module
    interface LoginAbstractModule {
        @FragmentScoped
        @ContributesAndroidInjector
        fun loginFragment(): LoginFragment
    }
}

Dependency injection is crucial for keeping your classes loosely coupled and easily testable. Dagger is one of the prime libraries in Android for such things, the other one being Koin.

The Dagger vs Koin war is an ongoing one, but despite the many controversies about Dagger, it’s multiple versions, and official-deprecation of dagger-android, Dagger still takes the lead when it comes to dependency injection, due to how easy it is to fall into bad practices with Koin.

Dagger does have a steep learning curve, and is quite complex. It doesn’t help that its documentation is very lackluster and that pretty much every single developer has a different way of implementing it.

Despite those shortcomings, Dagger in the right hands has the power to change the way a developer writes entire apps… literally.

And no matter how well you can argue that Koin is better than Dagger, if you don’t know how to use Dagger, you are by definition, an incompetent Android developer.

And yes, I do mean Dagger 2.

Link: https://github.com/google/dagger

1. Retrofit

public interface GitHubService {
  @GET("users/{user}/repos")
  Call<List<Repo>> listRepos(@Path("user") String user);
}

Retrofit turns your HTTP API calls into an interface. You use annotated methods to make your api calls in-app.

Retrofit does this one simple yet crucial job and does it extremely well. You have a wide array of annotations to use such as @Path, @Body, @QueryMap, and @Url to build your api calls.

When you build your Retrofit object, you can define your Base Url and add call adapters and converter factories as you see fit. It’s also easy to build for testing.

Its sheer simplicity, great documentation, testability, and usefulness earn it a very well deserved number one spot on this list, as well as a must for every Android developer to have in their toolbelts.

Almost every single app making any sort of API calls will be using this library. Jobs will require it. You will need to know it. That’s simply how amazing it is.

Link: https://square.github.io/retrofit/

 

Tags: