apk.fm / News / Discontinuing Kotlin synthetics for views

Discontinuing Kotlin synthetics for views

Discontinuing Kotlin synthetics for views

Posted by Márton Braun, Developer Relations Engineer


Artificial properties to entry views had been created as a technique to remove the widespread boilerplate of findViewById calls. These synthetics are supplied by JetBrains within the Kotlin Android Extensions Gradle plugin (to not be confused with Android KTX).

In November 2020, we introduced that this plugin has been deprecated in favor of higher options, and we really useful eradicating the plugin out of your initiatives. We all know many builders nonetheless depend upon this plugin’s options, and we’ve prolonged the assist timeframe so you’ve gotten extra time to finish your migrations.

We are actually setting a deadline for these migrations: the plugin can be eliminated in Kotlin 1.8, which is predicted to be launched by the finish of 2022. At the moment, you gained’t be capable of replace your undertaking to newer Kotlin variations if it nonetheless is determined by the Kotlin Android Extensions plugin. Which means that now could be the time to carry out the required migrations in your initiatives.

As an alternative of synthetics, we advocate utilizing View Binding, which generates type-safe binding lessons from XML structure information. These bindings present handy entry to view references and so they work safely for layouts with a number of configurations. See the migration information for detailed directions on learn how to undertake View Binding. In case you encounter any points, you possibly can report a bug on the Challenge Tracker.

When constructing new options, think about using Jetpack Compose, Android’s trendy UI toolkit. Layouts constructed with Compose are declarative Kotlin code, eliminating the necessity to work with view references.

One other function included within the plugin is Parcelize, which helps you create parcelable lessons. Parcelize is now obtainable within the standalone kotlin-parcelize plugin with unchanged performance. To stand up and operating with the brand new plugin, take a look at the Parcelize documentation web page.

In case you’re nonetheless utilizing the Kotlin Android Extensions Gradle plugin, kick off your migration in time with the intention to hold upgrading to new Kotlin releases sooner or later. This may allow you to make use of the most recent language options and benefit from tooling and compiler enhancements.

Source hyperlink

Take a comment