mardi 6 février 2018

Android KTX is a set of extensions to help developers write cleaner Kotlin code

Back in May of 2017 Google announced a new update to Android Studio Canary 1 for Android developers. The headline feature of this new version of Google’s IDE was the addition of first-class support of the Kotlin programming language. As developers have begun experimenting with using Kotlin to write their Android applications, many are seeing the added benefit of switching over from Java. This week, Google announced something new which should make writing in Kotlin even easier. It’s called Android KTX and it is a set of extensions designed to make writing Kotlin code for Android more concise, idiomatic, and pleasant.

Java can be a rather difficult programming language to pick up. This is even more true if it’s the first programming language that you have decided to learn. So the addition of Kotlin support in Android Studio was an attempt to make developing Android applications easier, thanks to Kotlin’s syntax. Kotlin can also be gradually integrated into existing products too so the transition from Java to Kotlin can be rather seamless.

With Android KTX, Google is now providing a nice API layer on top of both the Android framework as well as the Support Library.

In the announcement post Google has given us a collection of examples to show you how things differ between standard Kotlin code and with Android ATX. We’re told the other parts of Android KTX that cover the Android Support Library will be available in upcoming Support Library releases. Google says it’s very easy to start starting with Android ATX as you only need to add the following to your app module’s build.gradle file:

repositories {
google()
}

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

With that done, you can sync your project and the extensions appear automatically in the IDE’s auto-complete list. So as you begin working on your application, selecting an extension will automatically add the necessary import statement to your file. Also, Google points out that Android KTX uses package names that begin with androidx. This is to be expected as it is a new package name prefix that Google will be using in future versions of Android Support Library.

As this is in a preview phase right now, the feature will evolve over time but the portion of Android KTX that covers the Android framework is now available in Google’s GitHub repo.


Source: Google



from xda-developers http://ift.tt/2nOOSYF
via IFTTT

Aucun commentaire:

Enregistrer un commentaire