This article was translated from Japanese by Claude Code.
※Notes and impressions as of June 14, 2018. I’ll add updates as they become available.
Parcelize is a compiler extension provided by Kotlin for Android development. By adding the @Parcelize annotation to a class implementing Parcelable, it automatically generates the code necessary for Parcelable implementation.
For details, see below:
The product I’m currently working on has been using Parceler as a Parcelable library. Recently, I found a tweet saying that the issue preventing installation on Android version 4.3 devices had been fixed. Since we were in the middle of a feature refactor, I decided to adopt it.
横からすみません。4.3以下だとインストールできない件ですよね? 最近のバージョンでは直ってたと思います。https://t.co/stWooYXl2k
— Tsuyoshi UEHARA (@uecchi) June 1, 2018
Impressions#
Using it in Android Studio, it appears to be working without issues so far. You can easily check what code is generated using “Show Kotlin Bytecode”.
Notes#
Lint Error During Execution#
Currently, when you run lint on a class with the @Parcelize annotation, an error is thrown:
"This class implements Parcelable but does not provide a CREATOR field"(There was also a similar Warning in Android Studio, but that’s already been fixed.)
There seem to be two workarounds for this lint error. One is to completely ignore the error.
android {
lintOptions {
abortOnError false
}
}However, this setting ignores all lint errors, which doesn’t seem ideal.
Another approach is to add the @SuppressLint annotation to just the target class.
This was mentioned in the comments on the Issue Tracker:
https://youtrack.jetbrains.com/issue/KT-19300#comment=27-2853193
Here’s an example:
@SuppressLint("ParcelCreator")
@Parcelize
class MyParcelable(val data: Int): ParcelableIdeally, I wouldn’t want to add this annotation at all, but as a temporary workaround, this felt the most natural.
If you know of a better approach, I’d appreciate it if you could share it. m(__)m
※Update 06/14 (Thursday)
lintOptions {
ignore "ParcelCreator"
}It’s also possible to configure it to ignore ParcelCreator-related lint errors like this! Thanks @stsn_jp m(__)m
lintOptions {
— Sato Shun 🍑 (@stsn_jp) June 14, 2018
ignore "ParcelCreator"
}
みたいに書くことも出来たはず
View Binding Also Gets Enabled#
To use Parcelize, you need to enable Kotlin Android Extensions. Currently, when you enable this, View Binding is automatically enabled as well. For projects using Data Binding, there’s a need to keep View Binding disabled. I’m hoping that in the future, there will be a setting to enable only Parcelize.
※Update 06/18 (Monday)
Kotlin Android experimental, Parcelizeだけ有効にして欲しいにゃあって思っていたけど、あるっぽいhttps://t.co/mFa48KI6G4
— Sato Shun 🍑 (@stsn_jp) June 18, 2018
androidExtensions {
experimental = true
features = ["parcelize"]
}It looks like you can enable only Parcelize with this configuration. Thanks @stsn_jp!
Summary#
Parcelize looks good so far. I plan to replace Parceler (which we’re currently using) in my project.
Current issues are the “ParcelCreator” lint error and View Binding also being enabled, so we need to be careful about those.
※06/18 (Monday) Update: The method to enable only Parcelize is described above
For the lint error, using
@SuppressLint("ParcelCreator")individually seems best.
That’s all.