Skip to main content

Google launches Android KTX preview, a set of Kotlin extensions for developers

Google today introduced Android KTX, a set of extensions to help developers write Kotlin code for Android that is “more concise, idiomatic, and pleasant.” The company promises to iterate on the API “over the next few months” based on developer contributions and feedback.

At its I/O 2017 developer conference in May, Google announced Android officially supports the Kotlin programming language, in addition to Java and C++. Android Studio 3.0 with Kotlin support followed in May.

Currently in preview, Android KTX provides an API layer on top of the Android framework and Support Library — the former is available now on GitHub. Google promises to make the other parts of Android KTX that cover the Android Support Library available in upcoming Support Library releases.

To start using Android KTX in your Android Kotlin projects, add the following to your app module’s build.gradle file:
repositories {
google()
}


June 5th: The AI Audit in NYC

Join us next week in NYC to engage with top executive leaders, delving into strategies for auditing AI models to ensure fairness, optimal performance, and ethical compliance across diverse organizations. Secure your attendance for this exclusive invite-only event.


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

After you sync your project, the extensions will appear automatically in the IDE’s autocomplete list, and choosing any of them will add the necessary import statement to your file.

Google warns that the APIs are likely to change during the preview period. In other words, developers should not use it in their main Android projects, as there will be breaking changes before the stable version arrives. When the API has stabilized and Google commits to API compatibility, Android KTX will be released as part of the Android Support Library.

Android KTX uses package names that begin with androidx. Google also shared today that this is the new package name prefix for future versions of Android Support Library. The division between android.* and androidx.* is meant to help differentiate which APIs are bundled with the platform and which are static libraries for app developers that work across different versions of Android.

If you are interested in providing contributions and feedback on Android KTX, check out the “How to Contribute” section on GitHub.