How do I replace annotation class Parcelize
from package kotlinx.android.parcel
with Parcelize which is not coming from the kotlin-android-extensions plugin?
Kotlin Android Extensions is deprecated, which means that using Kotlin synthetics for view binding is no longer supported.
They are not supported with Java. There are still projects that are written in Java and may not be fully migrated to Kotlin yet, and hence Kotlin Synthetics may not be a consistent way of getting the ViewIds in your project. Because of these issues, Kotlin Synthetics is now being deprecated.
Usage. Just add the @Parcelize annotation to a class implementing the Parcelable interface and the Parcelable implementation will be generated automatically. This is the same example as in the previous article, in just 2 lines of code. The class can be a data class but it's optional.
What about the Parcelize feature from Kotlin Android Extensions? Don’t forget that Parcelize feature in Kotlin is part of the kotlin-android-extensions compiler plugin, so removing the plugin will endup making all your Parcelable classes not compiling if they depend on the Parcelize annotation.
In Kotlin 1.4.20-M2 JetBrains deprecated Kotlin Android Extensions compiler plugin. Actually this was expected long time ago, in this commit you can see kotlinx.android.synthetic is no longer a recommended practice. Removing in favour of explicit findViewById But why?
The kotlin-parcelize plugin provides a Parcelable implementation generator. When you annotate a class with @Parcelize, a Parcelable implementation is automatically generated, as shown in the following example: @Parcelize requires all serialized properties to be declared in the primary constructor.
Configuring Android Fragments with @Parcelize 1 Parcelable. Parcelable is an Android interface that allows you to serialize a custom type by manually writing/reading its data to/from a byte array. 2 Kotlin Android Extensions. ... 3 Combining @Parcelize and Fragments. ...
This should be the new plugin: https://plugins.gradle.org/plugin/org.jetbrains.kotlin.plugin.parcelize
If using Plugins DSL you can use the plugin ID in submodules. Make sure that the latest Kotlin Android plugin is available from the project's classpath.
// project build.gradle plugins { .. id "org.jetbrains.kotlin.android" version "1.4.20" apply false } // app build.gradle plugins { .. id 'kotlin-parcelize' }
When using kts you can write ->
// project build.gradle.kts plugins { .. kotlin("android") version "1.4.20" apply false } // app build.gradle.kts plugins { .. id("kotlin-parcelize") }
--- OR Legacy Plugin Application ---
Step 1. Update to latest kotlin version - 1.4.20
and replace
apply plugin: 'kotlin-android-extensions'
with this ->
apply plugin: 'kotlin-parcelize'
Step 2. Remove this code from the android {}
androidExtensions { experimental = true }
Step 3. Finally, replace old import ->
import kotlinx.android.parcel.Parcelize
with new import
import kotlinx.parcelize.Parcelize
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With