Android developers get programming extensions for Kotlin
The beta Android KTX extensions should make coding in Kotlin more concise and idiomatic
Having endorsed Kotlin as a language for Android development last year, Google is now previewing beta extensions to improve the Kotlin development experience. Called Android KTX, the extensions are designed to make writing Kotlin code more concise and idiomatic. An API layer is provided to work on top of Android’s framework and support library. KTX marks the first time Google has released a library specifically for Kotlin developers. KTX, however, is not intended to add new features to Android APIs.
Features in Android KTX
Android’s platform developers say KTX simplifies code in many cases. For example:
- KTX adds an extension function to the Android String class enabling more-natural conversion of strings to URIs.
- When editing SharedPreferences, which provides an interface to access and modify preference data, KTX code is shorter and more natural to read and write.
- Less code also would be needed when translating the difference between two paths in an Android program.
KTX package names begin with
androidx, a new prefix to be used in future versions of the support library. KTX proponents hope the division between
android.* 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. During the course of the beta period, the APIs could change. The project’s developers pledge that when KTX reaches 1.0 production status they will be rigorous and careful about maintaining API compatibility. You can offer feedback on Android KTX via an issue tracker.
Where to download Android KTX
To get started using the KTX library, download the binary file from Google’s Maven repo and add the dependency
androidxcore:core-ktx:0.1 in the build.gradle file of your Android Kotlin project. To use the repo, include
google() in that file. You can download the source code for the part of Android KTX that works with the Android framework from a Github repo.
View original article: here