After switching to Gradle Kotlin DSL Gradle is not able to resolve @Parcelize
annotation or package import kotlinx.android.parcel.Parcelize
("Unresolved reference" error). That happens with stable Kotlin plugin and latest Canary one. Build fails in Android Studio and also from console when using Gradle Wrapper.
Top level build.gradle.kts
buildscript {
repositories {
google()
mavenCentral()
jcenter()
}
dependencies {
classpath("com.android.tools.build:gradle:3.2.1")
classpath(kotlin("gradle-plugin", version = "1.3.11"))
}
}
allprojects {
repositories {
google()
mavenCentral()
jcenter()
}
}
App build.gradle.kts
import org.jetbrains.kotlin.config.KotlinCompilerVersion
plugins {
id("com.android.application")
kotlin("android")
kotlin("android.extensions")
}
android {
compileSdkVersion(28)
defaultConfig {
applicationId = "com.a.b.c"
minSdkVersion(15)
targetSdkVersion(28)
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
getByName("release") {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
}
}
// experimental mode is enabled -> @Parcelize should be resolved
androidExtensions {
isExperimental = true
}
}
dependencies {
implementation(kotlin("stdlib-jdk7", KotlinCompilerVersion.VERSION))
... other dependencies ...
I tried moving
androidExtensions {
isExperimental = true
}
from android to top level but still outcome was the same. Anyone had similar issue and managed to solve this?
Configuring Android Fragments with @Parcelize 1 Parcelable. Parcelable is an Android interface that allows you to serialize a custom type by manually writing/reading its data to/from a byte array. 2 Kotlin Android Extensions. ... 3 Combining @Parcelize and Fragments. ...
With kotlin-android-extensions we can implement Parcelable in much simpler way using @Parcelize and Parcelable. Android extensions are not considered production-ready yet, so we need to turn experimental mode on in app's build.gradle file
You also need to add apply plugin: ‘kotlin-android-extensions’ to your gradle file. However, if you have created your project using Kotlin support, it should be added automatically. Then add @Parcelize annotation to your model. That’s it!
After switching to Gradle Kotlin DSL Gradle is not able to resolve @Parcelize annotation or package import kotlinx.android.parcel.Parcelize ("Unresolved reference" error). That happens with stable Kotlin plugin and latest Canary one. Build fails in Android Studio and also from console when using Gradle Wrapper.
All you need to do is add below plugin to your app level gradle file
apply plugin: 'kotlin-parcelize'
PS: apply plugin: 'kotlin-android-extensions'
is deprecated.
In my case. Just swap 2 line of code kotlin-android and kotlin-android-extensions then it work.
So the sequence below is work:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With