2

Note, in case someone thinks this is a duplicate: I have seen Class X is not abstract and does not implement fun writeToParcel() defined in android.os.Parcelable - but it does not work for me in this case, which is why I post this question again (also, I have found a full project that can be downloaded and tested - that is, a "minimal (non)working example").

I have found an Android project I want to build, which fails with "Class 'X' is not abstract and does not implement abstract member public abstract fun writeToParcel".

I was trying to find a small example, that would reproduce this behavior, and I found the article https://android.jlelse.eu/yet-another-awesome-kotlin-feature-parcelize-5439718ba220 , with the related project on Github: https://github.com/burakeregar/KotlinParcelize .

Turns out, I had great difficulties to compile this, which can be seen here: How can I build this gradle project (KotlinParcelize) from the command line (Ubuntu 18.04, fail: Wrong plugin option format)?

However, I managed to update some of its libraries by opening it in Android Studio 4.0.1 - and now it reproduces the exact same error. I have saved this project in a branch in a fork of the original project - and now I can reproduce the same error by cloning this branch. This is what I do in the Ubuntu 18.04 command line:

$ cd /tmp/

$ git clone https://github.com/sdaau/KotlinParcelize.git KotlinParcelize_git
Cloning into 'KotlinParcelize_git'...
remote: Enumerating objects: 18, done.
remote: Counting objects: 100% (18/18), done.
remote: Compressing objects: 100% (16/16), done.
remote: Total 93 (delta 0), reused 9 (delta 0), pack-reused 75
Unpacking objects: 100% (93/93), done.

$ cd KotlinParcelize_git/

$ git checkout sdaau-android-studio-4.0.1-conv 
Branch 'sdaau-android-studio-4.0.1-conv' set up to track remote branch 'sdaau-android-studio-4.0.1-conv' from 'origin'.
Switched to a new branch 'sdaau-android-studio-4.0.1-conv'

# specify the path to the Android SDK on your system in `local.properties` file:
$ echo "sdk.dir=$HOME/Android/Sdk" | tee local.properties 
sdk.dir=/home/user/Android/Sdk


$ ./gradlew --stop
Stopping Daemon(s)
1 Daemon stopped

$ pkill -9 -f gradle
$ pkill -9 -f kotlin

$ pgrep -fl kotlin
$ pgrep -fl gradle

$ ./gradlew assembleDebug
Starting a Gradle Daemon, 2 stopped Daemons could not be reused, use --status for details

> Task :app:compileDebugKotlin FAILED
e: /tmp/KotlinParcelize_git/app/src/main/java/com/burakeregar/kotlinparcelize/PersonModel.kt: (13, 6): Class 'PersonModel' is not abstract and does not implement abstract member public abstract fun writeToParcel(p0: Parcel!, p1: Int): Unit defined in android.os.Parcelable

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugKotlin'.
> Compilation error. See log for more details

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 15s
9 actionable tasks: 9 executed

So, here is my question - there is a whole article and supporting code, that confirms that a construct like:

@Parcelize
data class PersonModel(val name: String, val age: Int) : Parcelable

... used to work fine, some versions ago.

Yet now, it fails with Class 'PersonModel' is not abstract and does not implement abstract member public abstract fun writeToParcel.

I have seen Class X is not abstract and does not implement fun writeToParcel() defined in android.os.Parcelable , and people were having similar issues, but as far as I see there, this is considered to be a fixed issue:

UPDATE 19/11/2019

After the stable release of Kotlin 1.3.60 and its corresponding Android Studio plugin the issue is no more. Let's celebrate

... but if you look in the above cloned repo branch:

$ grep ext.kotlin build.gradle 
    //ext.kotlin_version = '1.2.0'
    ext.kotlin_version = '1.3.72'

... you can see: 1.3.72 > 1.3.60, so I should not have a problem - right? And yet, it fails.

So - why do I get this problem; and which changes do I need to make (code or libraries) to have the @Parcelize data class PersonModel to compile correctly?

sdaau
  • 36,975
  • 46
  • 198
  • 278
  • 1
    FWIW, your test branch built fine here. Differences in what I did: I did not rename the clone directory to `KotlinParcelize_git`, I did not do the `echo` or the `pkill` commands, and I used `gradle` (a local Gradle installation) instead of `./gradlew`. – CommonsWare Sep 06 '20 at 16:44
  • Many thanks @CommonsWare - that's a great data point! Interestingly, I don't have a local `gradle` installation (at least, when I type `gradle` I get `Command 'gradle' not found`), so will give these changes a try. – sdaau Sep 06 '20 at 16:49
  • 1
    FWIW, my local Gradle installation is 6.3. Also, I had a copy of Android Studio 4.0.1 running at the time (though I did not import your project and built it from the command line as I mentioned). My best guess is that there is some environment difference that would explain the discrepancy in our results. Also, FWIW, my current client has a dozen or two `@Parcelize` classes, and we have not had problems building and using them. – CommonsWare Sep 06 '20 at 16:57
  • I am still facing this issue with kotlin_version = 1.4.32 – Namrata Bagerwal Mar 30 '21 at 13:26

0 Answers0