The new extentions are here

Android KTX makes Kotlin coding an absolute delight

Eirini-Eleni Papadopoulou
© Shutterstock / By Bakhtiar Zein  

On February 5th, Android Developers announced the preview of Android KTX, a set of extensions designed to make your Kotlin coding for Android as smooth as a summer’s sail.

Kotlin is one of the most popular kids on the playground! It did not take long for the community to become fascinated with this language and Google’s announcement in May 2017 on making Kotlin an officially supported language for developing apps, made it hit the top of the tops!

It doesn’t really matter that Kotlin lost to C in the run for the number one programming language for 2017, according to TIOBE Index. Kotlin conquers new ground in the programming world every day, becoming a real winner in our hearts (and our coding platforms!).

Kotlin, first developed in 2012, is still a baby in the programming ecosystem, however, it already has attributes and features that surpass many of its older cousins. Kotlin is officially described as concise, drastically reducing the amount of boilerplate code; safe, because it avoids entire classes of errors such as null pointer exceptions; interoperable for leveraging existing libraries for JVM, Android, and the browser; and tool-friendly thanks to its capability to choose any Java IDE or build from the command line.

If you want to learn more about how to get started with Kotlin, visit the official website. And for those of you who are already in love with it, here are some tips & tricks presented by JetBrains’ Dmitry Jemerov for JAXenter readers.

But let’s have a closer look at Android KTX.

SEE ALSO: Kotlin Team AMA highlights: Kotlin vs. Java, “under construction” features and more

Delighted coding with you, sir!

Android KTX provides a platform for smoother Kotlin coding. According to the official release announcement, the extensions are promised to make coding with Kotlin more “concise, idiomatic, and pleasant”. The extensions provide an API layer on top of both Android framework and Support Library.

To give you a small example, in the code below you see the translation of the difference between two paths by 100px.


 val pathDifference = Path(myPath1).apply {
   op(myPath2, Path.Op.DIFFERENCE)

val myPaint = Paint()

canvas.apply {
   val checkpoint = save()
   translate(0F, 100F)
   drawPath(pathDifference, myPaint)

Kotlin with Android KTX

 val pathDifference = myPath1 - myPath2

canvas.withTranslation(y = 100F) {
   drawPath(pathDifference, myPaint)

Time to get started!

If you are eager to start using Android KTX in your Android Kotlin projects, the only thing you need to do is add the following to your app module’s build.gradle file:

 repositories {

dependencies {
    // Android KTX for framework API
    implementation 'androidx.core:core-ktx:0.1'

Simple as that, after you sync your project, the extensions appear automatically in the IDE’s auto-complete list. Selecting an extension automatically adds the necessary import statement to your file.

However, you should be aware that the APIs are likely to change during the preview period. As the developers stated, you should expect breaking changes before a stable version of Android KTX is reached.

Can’t wait to try it out? We wish you a great time coding and don’t forget to share your experiences with the JAXenter community!

Eirini-Eleni Papadopoulou
Eirini-Eleni Papadopoulou was the editor for Coming from an academic background in East Asian Studies, she decided that it was time to go back to her high-school hobby that was computer science and she dived into the development world. Other hobbies include esports and League of Legends, although she never managed to escape elo hell (yet), and she is a guest writer/analyst for competitive LoL at TGH.

Inline Feedbacks
View all comments