Save the date! Android Dev Summit is coming to Sunnyvale, CA on Oct 23-24, 2019.

Android KTX   Part of Android Jetpack.

Android KTX is a set of Kotlin extensions that is part of the Android Jetpack family. It optimizes Jetpack and Android platform APIs for Kotlin use. The purpose of Android KTX is to make Android development with Kotlin more concise, pleasant, and idiomatic by leveraging Kotlin language features such as extension functions/properties, lambdas, named parameters, and parameter default values. Android KTX does not add any new features to the existing Android APIs.

To learn more about Android KTX, see our DevBytes video.

Getting Started

To start using Android KTX, add the following to your project's build.gradle file:

repositories {

Android KTX is organized into modules. Each module contains one or more packages.

When you use a module, include a dependency for each Android KTX artifact in your app's build.gradle file. Remember to append the version to the artifact. For example, if you use the core-ktx module, the fully-formed dependency will look something like this:

dependencies {
    implementation 'androidx.core:core-ktx:1.0.0'


Android KTX is composed of the following Maven artifacts. For API reference documentation, click on the specific package name and see the Extension functions summary. Note that version numbers can change. To be sure you are using the latest available version, check the Google Maven Repository.

Module (artifact) Version Package
androidx.core:core-ktx 1.0.0 See all the core packages below.
androidx.fragment:fragment-ktx 1.0.0
androidx.palette:palette-ktx 1.0.0
androidx.sqlite:sqlite-ktx 2.0.0 androidx.sqlite.db
androidx.collection:collection-ktx 1.0.0 androidx.collection
androidx.lifecycle:lifecycle-viewmodel-ktx 2.0.0 androidx.lifecycle
androidx.lifecycle:lifecycle-reactivestreams-ktx 2.0.0 androidx.lifecycle
android.arch.navigation:navigation-common-ktx 1.0.0-alpha06 androidx.navigation
android.arch.navigation:navigation-fragment-ktx 1.0.0-alpha06 androidx.navigation.fragment
android.arch.navigation:navigation-runtime-ktx 1.0.0-alpha06 androidx.navigation
android.arch.navigation:navigation-testing-ktx 1.0.0-alpha06 androidx.navigation.testing
android.arch.navigation:navigation-ui-ktx 1.0.0-alpha06 androidx.navigation.ui 1.0.0-alpha10

The core module includes these packages:


Android KTX is used in the Sunflower demo app.

The examples below demonstrate a few of the Android KTX extension functions. They are grouped by module (artifact) name. See the complete package reference documentation for the full list of extension functions.



    .putBoolean("key", value)

Kotlin + Android KTX

sharedPreferences.edit {
    putBoolean("key", value)


    object : ViewTreeObserver.OnPreDrawListener {
        override fun onPreDraw(): Boolean {
            return true

Kotlin + Android KTX

view.doOnPreDraw {



try {
    // insert data
} finally {

Kotlin + Android KTX

db.transaction {
    // insert data



    .replace(, myFragment, FRAGMENT_TAG)

Kotlin + Android KTX

supportFragmentManager.transaction(allowStateLoss = true) {
            replace(, myFragment, FRAGMENT_TAG)


We will continue to add new Kotlin extensions throughout Jetpack and we welcome your feedback. If you would like to report an issue or suggest a feature, please file a new issue at the Android KTX issue tracker.