No noarg super constructor for CLASS CLASS

Viewed 133

Kotlin 1.5.0

I have a error when trying to build my android app after bumping the kotlin version to 1.5.0.

I am thinking its related to having a parcelized class and using the no-arg plugin.

I have the following class

import android.os.Parcelable
import kotlinx.parcelize.Parcelize

sealed class CDSAppbarProfile(
    val count: Int
) : Parcelable {
    @Parcelize
    class User(
        val origincount: Int,
        val imageUrl: String
    ) : Parcelable, CDSAppbarProfile(origincount)

    @Parcelize
    class Guest(
        val origincount: Int
    ) : Parcelable, CDSAppbarProfile(origincount)
}

And I am getting this error:

IllegalStateException: No noarg super constructor for CLASS CLASS name:User modality:FINAL visibility:public superTypes:[android.os.Parcelable; com.centraldepartment.app.base.model.CDSAppbarProfile]:
CONSTRUCTOR visibility:protected <> (count:kotlin.Int) returnType:com.centraldepartment.app.base.model.CDSAppbarProfile [primary]
        at org.jetbrains.kotlin.noarg.NoArgIrTransformer.getOrGenerateNoArgConstructor(NoArgIrGenerationExtension.kt:76)

This error occured when I updated our kotlin version from 1.4.32 to 1.5.0

distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip

This is my build.gradle(project)

buildscript {
    ext.kotlin_version = '1.5.0'
    ext.navigationVersion = '2.3.3'
    ext.jacocoVersion = "0.8.5"
    ext.daggerHiltVersion = "2.37"

    repositories {
        google()
        jcenter()
        maven { url "https://jitpack.io" }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:4.2.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "org.jetbrains.kotlin:kotlin-noarg:$kotlin_version"
        classpath "org.jacoco:org.jacoco.core:$jacocoVersion"
        classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$navigationVersion"
        classpath 'com.google.gms:google-services:4.3.5'
        classpath 'com.google.firebase:perf-plugin:1.3.4'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.5.0'
        classpath "com.google.dagger:hilt-android-gradle-plugin:$daggerHiltVersion"
    }
}

And in my build.gradle (app) I have the following:

apply plugin: "kotlin-noarg"

noArg {
    annotation("kotlinx.parcelize.Parcelize")
    invokeInitializers = true
}
1 Answers

This is indeed a bug in no-arg plugin.

There is a bug open on in already for a year on Jetbrain's youtrack - KT-46537.

There are currently no workarounds provided.

Related