我在很长一段时间里一直在使用Kotlin 1.3.21,在很长一段时间里一直在实验模式下使用kotlin-android-extensions个插件.今天,我仅仅通过碰撞版本就切换到了Kotlin 1.3.30,现在无论我在哪里使用@Parcelize注释,我都会看到错误:

以下是我如何启用android扩展:

apply plugin: 'kotlin-android-extensions'

androidExtensions {
    experimental = true
    features = ["parcelize"]
}

请注意,我没有明确声明所需的特性就try 了,但效果并不理想.

还要注意,我使用的是Grrovy Gradle DSL.

How can I enable Parcelizeback with Kotlin 1.3.30?

EDIT Here's my app level build.gradle

apply plugin: 'com.android.application'
apply plugin: "de.mannodermaus.android-junit5"
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'

apply from: "../versions.gradle"

android {

    compileSdkVersion 28

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        applicationId "com.myapp.dtt"
        minSdkVersion 18
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"

        vectorDrawables.useSupportLibrary = true
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
        test.java.srcDirs += 'src/test/kotlin'
        androidTest.java.srcDirs += 'src/androidTest/kotlin'
    }

    testOptions {
        junitPlatform {
            filters {
                engines {
                    include 'spek2'
                }
            }
        }
    }
}

detekt {
    input = files("src/main/kotlin")
    baseline = file("detekt-baseline.xml")
}

androidExtensions {
    experimental = true
    features = ["parcelize"]
}

dependencies {
    kapt "com.google.dagger:dagger-compiler:$dagger_version"
    kapt "com.google.dagger:dagger-android-processor:$dagger_version"
    kapt "com.github.bumptech.glide:compiler:$glide_version"

    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
    implementation "com.google.android.material:material:$material_version"
    implementation "androidx.lifecycle:lifecycle-runtime:$lifecycle_version"
    implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version"
    implementation "androidx.appcompat:appcompat:$appcompat_version"
    implementation "androidx.recyclerview:recyclerview:$recyclerview_version"
    implementation "androidx.constraintlayout:constraintlayout:$constraint_layout_version"
    implementation "com.google.dagger:dagger:$dagger_version"
    implementation "com.google.dagger:dagger-android:$dagger_version"
    implementation "com.google.dagger:dagger-android-support:$dagger_version"
    implementation "io.reactivex.rxjava2:rxjava:$rx_java_version"
    implementation "io.reactivex.rxjava2:rxandroid:$rx_android_version"
    implementation "io.reactivex.rxjava2:rxkotlin:$rx_kotlin_version"
    implementation "com.github.bumptech.glide:glide:$glide_version"

    debugImplementation "com.squareup.leakcanary:leakcanary-android:$leak_canary_version"
    releaseImplementation "com.squareup.leakcanary:leakcanary-android-no-op:$leak_canary_version"

    testImplementation "org.spekframework.spek2:spek-dsl-jvm:$spek_version"
    testImplementation "org.spekframework.spek2:spek-runner-junit5:$spek_version"
    testImplementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
    testImplementation "org.junit.jupiter:junit-jupiter-api:$junit_jupiter_version"
    testImplementation "io.mockk:mockk:$mockk_version"
    testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junit_jupiter_version"
}

推荐答案

我发现了错误

Kotlin plugin should be enabled before 'kotlin-android-extensions'

因此将顺序更改为

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

it work fine (:з」∠) .

good luck to you.

Kotlin相关问答推荐

我如何测试一个可组合组件没有显示,但如果它不存在也接受?

Kotlin编译器如何决定是否可以在任何给定点调用Suspend方法?

我需要后台工作才能使用卡夫卡的消息吗?

Spring Boot 3:为Kotlin中的TestRestTemplate配置读取超时

如何在Spring Boot中注册新的集合工厂

为什么使用 return instance ?: synchronized(this) { instance ?: PreferenceParameterState(context) } 时无法获得单例?

Kotlin - 如何避免在密封类的 when() 语句中转换第二个变量

Webpack 配置未应用于 kotlin 多平台react 项目

如何处理基于枚举提前返回的 forEach 循环,Kotlin 中的一条路径除外

如果不为空,则为 builder 设置一个值 - Kotlin

Kotlin 日期格式从一种更改为另一种

无法从 XML 访问 NavHostFragment

Kotlin boxed Int 不一样

Jetpack Compose State:修改类属性

Kapt不适用于Android Studio 3.0中的AutoValue

如何从kotlin中的类实例化对象

如何在Kotlin中使用ViewModelProviders

TypeConverter()在Android的TypeConverter错误中具有私有访问权限

Kotlin中的属性(properties)和参数(parameters)有什么区别?

如何根据ArrayList的对象属性值从中获取最小/最大值?