My experiences using Anko library (Android Kotlin)


I’ve been using Anko library from the start of my Kotlin journey and my experiences with it are mostly positive.

According to its Github readme page, Anko is

...a Kotlin library which makes Android application development faster and easier. It makes your code clean and easy to read, and lets you forget about rough edges of the Android SDK for Java.

Anko consists of several parts:

- Anko Commons: a lightweight library full of helpers for intents, dialogs, logging and so on;
- Anko Layouts: a fast and type-safe way to write dynamic Android layouts;
- Anko SQLite: a query DSL and parser collection for Android SQLite;
- Anko Coroutines: utilities based on the kotlinx.coroutines library.

It provides basic guide for getting started.

Where I find Anko the most valuable is when dealing with SQLite and creating dialogs.

  • When dealing with SQLite, you don’t need to worry about closing the database after querying it, concurrent access, creating cursors.
  • Dialogs simplifies Android development so much because it eliminates all boilerplate associated with connecting dialog fragment to activity and dialog-activity communication with after user interacted with the dialog.

I don’t like its layouts component though. Because:

  • it encourage mixing logic with presentation,
  • it doesn’t work so nicely with complex layouts,
  • it has no layout preview.

But because pros of using the library out-weights the cons, I’m willing to rate my experience with the library positively. I haven’t refrained from using its layouts component, just limited its usage to simple use cases.