spot_img
HomeEducationStrive the K2 compiler in your Android tasks Acquire US

Strive the K2 compiler in your Android tasks Acquire US

Posted by Márton Braun, Developer Relations Engineer

Strive the K2 compiler in your Android tasks Acquire US Obtain US

The Kotlin compiler is being rewritten for Kotlin 2.0. The brand new compiler implementation–codenamed K2–brings with it vital construct pace enhancements, compiling Kotlin code as much as twice as quick as the unique compiler. It additionally has a extra versatile structure that may allow the introduction of recent language options after 2.0.

Strive the brand new compiler

With Kotlin 1.9, K2 is now out there in Beta for JVM targets, together with Android tasks. To assist stabilize the brand new compiler and be sure to’re prepared for Kotlin 2.0, we encourage you to attempt compiling your tasks with the brand new compiler. When you run into any points, you possibly can report them on the Kotlin issue tracker.

To attempt the brand new compiler, replace to Kotlin 1.9 and add the next to your mission’s gradle.properties file:

kotlin.experimental.tryK2=true

Observe that the brand new compiler shouldn’t be used for manufacturing builds but. An excellent strategy for attempting it early is to create a separate department in your mission for compiling with K2. Yow will discover an example of this within the Now in Android repository.

Tooling assist

Plugins and instruments that rely on the Kotlin compiler frontend can even should be up to date so as to add assist for K2. Some instruments have already got experimental assist for constructing with K2: the Jetpack Compose compiler plugin helps K2 beginning in 1.5.0, which is compatible with Kotlin 1.9.

Android Lint additionally helps K2 beginning in model 8.2.0-alpha12. To run Lint on K2, improve to this model and add android.lint.useK2Uast=true to your gradle.properties file. Observe that any customized lint guidelines that depend on APIs from the previous frontend must be up to date to make use of the analysis API as a substitute.

Including K2 assist in different instruments remains to be in progress: KSP and KAPT duties at present fall again to utilizing the previous compiler when constructing your mission with K2. Nonetheless, compilation duties can nonetheless run utilizing K2 when these instruments are used.

Android Studio additionally depends on the Kotlin compiler for code evaluation. Till Android Studio has assist for K2, constructing with K2 would possibly lead to some discrepancies between the code evaluation of the IDE and command line builds in sure edge circumstances.

When you use any further compiler plugins, verify their documentation to see whether or not they’re appropriate with K2 but.

Get began with the K2 compiler at present

The Kotlin 2.0 Compiler gives vital enhancements that will help you ship updates quicker, be extra productive, and spend extra time specializing in what makes your app distinctive.

It already works with Jetpack Compose and we now have a roadmap to enhance assist in different instruments, together with Android Studio, KSP, and compiler plugins. Now is a superb time to attempt it in your app’s codebase and supply suggestions associated to Kotlin, Compose, or Lint.

#compiler #Android #tasks

RELATED ARTICLES
Continue to the category

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -spot_img

Most Popular

Recent Comments