Kotlin 1.5.0
将Kotlin版本升级到1.5.0
后,尝试构建安卓应用时出现了错误。
我认为这可能与使用无参插件的序列化类有关。
以下是我的类:
import android.os.Parcelable
import kotlinx.parcelize.Parcelize
sealed class Profile(
val count: Int
) : Parcelable {
@Parcelize
class User(
val origincount: Int,
val imageUrl: String
) : Parcelable, Profile(origincount)
@Parcelize
class Guest(
val origincount: Int
) : Parcelable, Profile(origincount)
}
我遇到了以下错误:
IllegalStateException: No noarg super constructor for CLASS CLASS name:User modality:FINAL visibility:public superTypes:[android.os.Parcelable; com.centraldepartment.app.base.model.Profile]:
CONSTRUCTOR visibility:protected <> (count:kotlin.Int) returnType:com.centraldepartment.app.base.model.CDSAppbarProfile [primary]
at org.jetbrains.kotlin.noarg.NoArgIrTransformer.getOrGenerateNoArgConstructor(NoArgIrGenerationExtension.kt:76)
当我将kotlin版本从1.4.32
更新到1.5.0
时,出现了这个错误。
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip
这是我的build.gradle(项目)文件
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"
}
}
而在我的 build.gradle (app) 文件中,我有以下内容:
apply plugin: "kotlin-noarg"
noArg {
annotation("kotlinx.parcelize.Parcelize")
invokeInitializers = true
}