我使用 Kotlin 1.3.21 很长时间了kotlin-android-extensions
插件长期处于实验模式。今天我通过升级版本切换到 Kotlin 1.3.30,现在无论我使用什么@Parcelize
注释我看到错误:Unresolved reference: Parcelize
.
以下是我启用 Android 扩展的方法:
apply plugin: 'kotlin-android-extensions'
androidExtensions {
experimental = true
features = ["parcelize"]
}
请注意,我在没有明确声明所需功能的情况下进行了尝试,但效果不佳。
另请注意,我使用 Groovy Gradle DSL。
我怎样才能启用Parcelize
回到 Kotlin 1.3.30 了吗?
EDIT这是我的应用程序级别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'
效果很好(:з」∠) 。
祝你好运。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)