首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >更新至Kotlin 1.3.30后的“未解决的引用: Parcelize”

更新至Kotlin 1.3.30后的“未解决的引用: Parcelize”
EN

Stack Overflow用户
提问于 2019-04-20 09:57:23
回答 3查看 7.4K关注 0票数 19

我长期使用Kotlin1.3.21和kotlin-android-extensions插件在实验模式下。今天,我向Kotlin1.3.30起誓,只要跳过版本,现在无论我使用@Parcelize注释的地方,我都看到了错误:Unresolved reference: Parcelize

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

代码语言:javascript
运行
复制
apply plugin: 'kotlin-android-extensions'

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

注意,我尝试过而没有显式声明所需的特性,而且它也不起作用。

还请注意,我使用Grrovy Gradle DSL。

如何使用Kotlin1.3.30启用Parcelize

编辑这里是我的应用程序级build.gradle

代码语言:javascript
运行
复制
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"
}
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2019-04-23 02:02:38

我发现了错误

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

因此,将命令更改为

代码语言:javascript
运行
复制
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

它运行良好(:з“∠)。

祝你好运。

票数 67
EN

Stack Overflow用户

发布于 2020-01-10 07:58:04

我将Kotlin插件升级到最新版本(1.3.61),这个错误被删除了。

票数 3
EN

Stack Overflow用户

发布于 2022-10-26 02:34:39

最新的kotlin版本要求这个插件使用@Parcelize:

代码语言:javascript
运行
复制
id 'kotlin-parcelize'

代码语言:javascript
运行
复制
apply plugin: 'kotlin-parcelize'
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55772345

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档