How Android KTX Extensions make coding in Kotlin easier



Google has released the beta of Android KTX, as extensions designed to ease coding in Kotlin, while the API layer works on top of Android’s framework and have library support.

Android KTX is perhaps the first time Google is making a library specifically for Kotlin developers, albeit it isn't bringing any new features to the Android APIs. Kotlin was openly endorsed by Google as a preferred language for Android development last year, the KTX beta extensions is meant to improve on the Kotlin development experience.

The KTX package begins with androidx, which is a new prefix used in latest versions of the support library. And the proponents hope it will make it more obvious which APIs are bundled with the platform and which are static libraries for developers working with different versions of Android.

According to the KTX developers, the APIs could change during the course of the beta period, but pledges that when KTX reaches 1.0 production status, maintaining API compatibility will be more thorough.

Some advantages of KTX in simplification of coding is as follows: Useful in SharedPreferences, which provides an interface to modify preference data, as the KTX code is shorter and more natural to read and write.

Also, the Android String class will enable more-natural conversion of strings to URIs through KTX extension, and less code would be required when translating the difference between two paths in an Android program.

The source code for the part of Android KTX that works with the Android framework can be downloaded from this Github repo. And developers who wish to give it a spin, can get started from the binary file from Google’s Maven repository and add the dependency androidxcore:core-ktx:0.1 in the build.gradle file of their Android Kotlin project.
Previous
Next Post »