Today I wanted to make a data class
a Parcelable so that I could pass it as an argument in Navigation component.
Parcelables, though better in performance than Serializables, take more time to implement! To help us out, there’s a “kotlin-parcelize” plugin that can generate the boilerplate code for us.
There were issues though.
After applying the kotlin-parcelize plugin, I was getting the error:
'kotlin-parcelize' can't be applied together with 'kotlin-android-extensions'
So kotlin-parcelize is like a “successor” to the now deprecated 'kotlin-android-extensions'
that I’m still using. So I replaced 'kotlin-android-extensions'
with ‘kotlin-parcelize’.
I got another error after attempting to sync with my Gradle files:
1 2 3 4 |
</code><code>org.gradle.api.GradleScriptException: A problem occurred evaluating project ':app' [...] Caused by: groovy.lang.MissingMethodException: No signature of method: build_54gmhuqjm83le8li4fspjsxlu.android() is applicable for argument types: (build_54gmhuqjm83le8li4fspjsxlu$_run_closure1) values: [build_54gmhuqjm83le8li4fspjsxlu$_run_closure1@3c374eea] at build_54gmhuqjm83le8li4fspjsxlu.run(<em>[...]</em>\app\build.gradle:11) |
The solution was to remove the following code from my android{}
block:
1 2 3 |
androidExtensions <strong>{ </strong>experimental = true <strong>}</strong> |
After removing that, Gradle synced successfull!
References:
Parcelable implementation generator
How to use @Parcelize now that kotlin-android-extensions is being deprecated?