Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upgrade from Kotlin 1.3.31 -> 1.3.40 breaks Android build

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?

like image 467
EntangledLoops Avatar asked Jun 22 '19 18:06

EntangledLoops


People also ask

How do I change my Kotlin Android version?

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.

How do I fix the module was compiled with an incompatible version of Kotlin the binary version of its metadata is 1/5 1 Expected version is 1 1 16?

It was fixed by updating the Kotlin Gradle plugin version. In the project level build.

How do I update my Kotlin?

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.


1 Answers

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.

like image 90
Alexey Belkov Avatar answered Oct 11 '22 10:10

Alexey Belkov