If I try to upgrade to the latest Kotlin version in my Gradle project, I get the following error building my Android subproject:
e: /(redacted)/AndroidLauncher.kt: (8, 15): Cannot access built-in declaration 'kotlin.Unit'. Ensure that you have a dependency on the Kotlin standard library
Downgrading back to 1.3.31 builds fine. I also tried upgrading my com.android.tools.build version from 3.4.0 -> 3.4.1, but no difference.
The error makes it pretty clear that there's trouble finding the Kotlin STL. Is there some new dependency I need to add or plugin I need to apply?
In your Android studio, Go to Tools -> Kotlin -> Configure Kotlin Updates. Save this answer. Show activity on this post. apply this fix to your top level build.
It was fixed by updating the Kotlin Gradle plugin version. In the project level build.
Update to a new release IntelliJ IDEA and Android Studio suggest updating to a new release once it is out. When you accept the suggestion, it automatically updates the Kotlin plugin to the new version. You can check the Kotlin version in Tools | Kotlin | Configure Kotlin Plugin Updates.
This behavior is the result of the recently fixed problem https://youtrack.jetbrains.com/issue/KT-19227. Previously, some built-in declarations like kotlin.Unit
were loaded from the compiler internals when the compiled module didn't have a dependency on the Kotlin stdlib. Currently such a situation causes the build to fail, which is a less surprising behavior.
To make your project compile again, add the implementation(kotlin("stdlib"))
dependency in your android
subproject.
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